本文整理汇总了Java中org.apache.commons.mail.MultiPartEmail.send方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPartEmail.send方法的具体用法?Java MultiPartEmail.send怎么用?Java MultiPartEmail.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.MultiPartEmail
的用法示例。
在下文中一共展示了MultiPartEmail.send方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmailAttachment
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void sendEmailAttachment(String email_to, String assunto, String msg, String file_logs) {
File fileLogs = new File(file_logs);
EmailAttachment attachmentLogs = new EmailAttachment();
attachmentLogs.setPath(fileLogs.getPath());
attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
attachmentLogs.setDescription("Logs");
attachmentLogs.setName(fileLogs.getName());
try {
MultiPartEmail email = new MultiPartEmail();
email.setDebug(debug);
email.setHostName(smtp);
email.addTo(email_to);
email.setFrom(email_from);
email.setAuthentication(email_from, email_password);
email.setSubject(assunto);
email.setMsg(msg);
email.setSSL(true);
email.attach(attachmentLogs);
email.send();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例2: prepareAndSend
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Prepare and send filejackets to the specified email address.
* <p>
* @param fileJackets files to be send
*/
private void prepareAndSend(List<FileJacket> fileJackets) {
SubMonitor m = monitorFactory.newSubMonitor("Transfer");
m.message("sending Mail");
m.start();
try {
ListingMailConfiguration config = listingService.get().listingMailConfiguration();
MultiPartEmail email = mandator.prepareDirectMail();
email.setFrom(config.getFromAddress());
email.addTo(config.getToAddress());
email.setSubject(config.getSubject());
email.setMsg(config.toMessage());
for (FileJacket fj : fileJackets) {
email.attach(
new javax.mail.util.ByteArrayDataSource(fj.getContent(), "application/xls"),
fj.getHead() + fj.getSuffix(), "Die Händlerliste für die Marke ");
}
email.send();
m.finish();
} catch (EmailException e) {
throw new RuntimeException(e);
}
}
示例3: send
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
@Override
public String send(Message msg) {
// See: http://stackoverflow.com/questions/21856211/javax-activation-unsupporteddatatypeexception-no-object-dch-for-mime-type-multi
currentThread().setContextClassLoader(getClass().getClassLoader());
MultiPartEmail mail = config.newMail();
try {
mail.setCharset(msg.getCharset().name());
addAddresses(mail.getToAddresses(), msg.getTo());
addAddresses(mail.getCcAddresses(), msg.getCc());
addAddresses(mail.getBccAddresses(), msg.getBcc());
addAttachments(mail, msg);
if (msg.getFrom() != null)
mail.setFrom(msg.getFrom());
mail.setSubject(msg.getSubject());
mail.setMsg(msg.getBody());
if (mail.getToAddresses().size() + mail.getCcAddresses().size() + mail.getBccAddresses().size() > 0)
return mail.send();
else
return "Mail not sent due to empty recipiants list.";
} catch (EmailException | AddressException e) {
throw new RuntimeException(e);
}
}
示例4: sendMultipartEmail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void sendMultipartEmail() throws MangooMailerException {
Config config = Application.getInstance(Config.class);
try {
MultiPartEmail multiPartEmail = new MultiPartEmail();
multiPartEmail.setCharset(Default.ENCODING.toString());
multiPartEmail.setHostName(config.getSmtpHost());
multiPartEmail.setSmtpPort(config.getSmtpPort());
multiPartEmail.setAuthenticator(getDefaultAuthenticator());
multiPartEmail.setSSLOnConnect(config.isSmtpSSL());
multiPartEmail.setFrom(this.from);
multiPartEmail.setSubject(this.subject);
multiPartEmail.setMsg(render());
for (String recipient : this.recipients) {
multiPartEmail.addTo(recipient);
}
for (String cc : this.ccRecipients) {
multiPartEmail.addCc(cc);
}
for (String bcc : this.bccRecipients) {
multiPartEmail.addBcc(bcc);
}
for (File file : this.files) {
multiPartEmail.attach(file);
}
multiPartEmail.send();
} catch (EmailException | MangooTemplateEngineException e) {
throw new MangooMailerException(e);
}
}
示例5: mail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* This method send document to the e-Mail address that is in the customer set.
* <p/>
* @param document This is the Document that will be send.
* @throws UserInfoException if the sending of the Mail is not successful.
* @throws RuntimeException if problems exist in the JasperExporter
*/
@Override
public void mail(Document document, DocumentViewType jtype) throws UserInfoException, RuntimeException {
UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
String customerMailAddress = customerService.asCustomerMetaData(document.getDossier().getCustomerId()).getEmail();
if ( customerMailAddress == null ) {
throw new UserInfoException("Kunde hat keine E-Mail Hinterlegt! Senden einer E-Mail ist nicht Möglich!");
}
String doctype = (jtype == DocumentViewType.DEFAULT ? document.getType().getName() : jtype.getName());
try (InputStream is = mandator.getMailTemplateLocation().toURL().openStream();
InputStreamReader templateReader = new InputStreamReader(is)) {
String text = new MailDocumentParameter(customer.toTitleNameLine(), doctype).eval(IOUtils.toString(templateReader));
MultiPartEmail email = mandator.prepareDirectMail();
email.setCharset("UTF-8");
email.addTo(customerMailAddress);
email.setSubject(document.getType().getName() + " | " + document.getDossier().getIdentifier());
email.setMsg(text + mandator.getDefaultMailSignature());
email.attach(
new ByteArrayDataSource(JasperExportManager.exportReportToPdf(jasper(document, jtype)), "application/pdf"),
"Dokument.pdf", "Das ist das Dokument zu Ihrem Aufrag als PDF.");
for (MandatorMailAttachment mma : mandator.getDefaultMailAttachment()) {
email.attach(mma.getAttachmentData().toURL(), mma.getAttachmentName(), mma.getAttachmentDescription());
}
email.send();
} catch (EmailException ex) {
L.error("Error on Mail sending", ex);
throw new UserInfoException("Das senden der Mail war nicht erfolgreich!\n" + ex.getMessage());
} catch (IOException | JRException e) {
throw new RuntimeException(e);
}
}
示例6: share
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void share()
{
MultiPartEmail email = new MultiPartEmail();
email.setHostName(GMAIL_SMTP_URL);
email.setSmtpPort(GMAIL_SMTP_PORT);
// needs gmail pass for from email
email.setAuthenticator(new DefaultAuthenticator(from, fromPassword));
email.setSSLOnConnect(true);
if(imagePath!=null && !imagePath.isEmpty()){
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(imagePath);
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(ATTACHMENT_DESC);
attachment.setName(ATTACHMENT_IMG_TITLE);
try {
email.attach(attachment);
} catch (Exception e1) {
e1.printStackTrace();
}
}
try{
email.setFrom(from);
email.setSubject(EMAIL_SUBJECT);
email.setMsg(message);
email.addTo(to);
email.send();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
示例7: sendSupportRequest
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public boolean sendSupportRequest() {
try {
String senderName = sender_name.getText();
String senderEmail = sender_email.getText();
String sendingTime = date_time.getText();
String systemUser = system_user.getText();
String message = messge_content.getText();
if (message.isEmpty()) {
JOptionPane.showMessageDialog(this, "You haven't entered your message. Please enter the message and try again.");
}
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("mail.mdcc.lk");
email.addTo("[email protected]", "Viraj @ MDCC");
email.addTo("[email protected]", "Isuru @ MDCC");
email.setFrom(senderEmail, senderName);
email.setAuthentication("[email protected]", "mdccmail123");
email.setSSLOnConnect(true);
email.setStartTLSEnabled(true);
email.setSmtpPort(465);
// email.setHostName("mail.mdcc.lk");
// email.addTo("[email protected]", "Isuru Ranawaka");
// email.setFrom("[email protected]", "Isuru Ranawaka from MDCC");
// email.setSubject("Test email with inline image");
// email.setAuthentication("[email protected]", "=-88isuru");
// email.setSSLOnConnect(false);
// email.setSmtpPort(25);
// email.setDebug(true);
email.setSubject("New Support Request from Application");
String textMessage = "Application - Support Request\n"
+ "---------------------------------------------------------------------\n"
+ "New Support Request from _P1_\n"
+ "Sent by _P2_ on _P3_\n"
+ "---------------------------------------------------------------------\n"
+ "\n"
+ "Message: \n_P4_\n"
+ "\n"
+ "---------------------------------------------------------------------\n"
+ "This email was sent from Application. \n"
+ "Please note that this is an automatically generated email and \n"
+ "your replies will go nowhere.\n"
+ "\n"
+ "© All Rights Reserved - Management Development Co-operative Co. Ltd.";
textMessage = textMessage.replace("_P1_", systemUser);
textMessage = textMessage.replace("_P2_", senderName + "(" + senderEmail + ")");
textMessage = textMessage.replace("_P3_", sendingTime);
textMessage = textMessage.replace("_P4_", message);
//attach file
if (!attachedFile.trim().isEmpty()) {
email.attach(new File(attachedFile));
}
// set the alternative message
email.setMsg(textMessage);
// send the email
email.send();
return true;
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Cannot send email.\nError:" + e.getLocalizedMessage(), "Sending failure", JOptionPane.ERROR_MESSAGE);
return false;
}
}
示例8: sendEmail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Sends an email with a PDF attachment.
* @throws TransportConfigurationException
* @throws EmailException
* @throws MessagingException
*/
public void sendEmail(String receipient, byte[] pdf) throws TransportConfigurationException, EmailException, MessagingException {
if(!configuration.isEnabled()) {
throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
}
final MultiPartEmail email = new MultiPartEmail();
email.setCharset(EmailConstants.UTF_8);
if (Strings.isNullOrEmpty(configuration.getHostname())) {
throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
} else {
email.setHostName(configuration.getHostname());
}
email.setSmtpPort(configuration.getPort());
if (configuration.isUseSsl()) {
email.setSslSmtpPort(Integer.toString(configuration.getPort()));
}
if(configuration.isUseAuth()) {
email.setAuthenticator(new DefaultAuthenticator(
Strings.nullToEmpty(configuration.getUsername()),
Strings.nullToEmpty(configuration.getPassword())
));
}
email.setSSLOnConnect(configuration.isUseSsl());
email.setStartTLSEnabled(configuration.isUseTls());
if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) {
email.setFrom(pluginConfig.getString("sender"));
} else {
email.setFrom(configuration.getFromEmail());
}
email.setSubject("Graylog Aggregates Report");
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
email.attach(new ByteArrayDataSource(pdf, "application/pdf"),
"aggregates_report_" + df.format(c.getTime()) +".pdf", "Graylog Aggregates Report",
EmailAttachment.ATTACHMENT);
email.setMsg("Please find the report attached.");
email.addTo(receipient);
LOG.debug("sending report to " + email.getToAddresses().toString());
email.send();
}
示例9: send
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Send.
*
* @param mailInfo
* the mail info
* @throws EmailException
* the email exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void send(final MailInfo mailInfo) throws EmailException, IOException {
final MultiPartEmail email = new MultiPartEmail();
email.setCharset("utf-8");
mailInfo.fillEmail(email);
email.send();
}