List of usage examples for org.apache.commons.mail HtmlEmail setMsg
@Override public Email setMsg(final String msg) throws EmailException
From source file:nl.b3p.kaartenbalie.struts.Mailer.java
public ActionMessages send(ActionMessages errors) throws AddressException, MessagingException, IOException, Exception { HtmlEmail email = new HtmlEmail(); String[] ds = null;/*from w w w .j av a2 s . c o m*/ if (mailTo != null && mailTo.trim().length() != 0) { ds = mailTo.split(","); for (int i = 0; i < ds.length; i++) { email.addTo(ds[i]); } } if (mailCc != null && mailCc.trim().length() != 0) { ds = mailCc.split(","); for (int i = 0; i < ds.length; i++) { email.addCc(ds[i]); } } if (mailBcc != null && mailBcc.trim().length() != 0) { ds = mailBcc.split(","); for (int i = 0; i < ds.length; i++) { email.addBcc(ds[i]); } } email.setFrom(mailFrom); email.setSubject(subject); email.setHostName(mailHost); if (isReturnReceipt()) { email.addHeader("Disposition-Notification-To", mailFrom); } if (attachmentName == null) { attachmentName = "attachment"; } if (attachment != null) { URL attachUrl = null; try { attachUrl = new URL(attachment); email.attach(attachUrl, attachmentName, attachmentName); } catch (MalformedURLException mfue) { } } if (attachmentDataSource != null) { email.attach(attachmentDataSource, attachmentName, attachmentName); } email.setMsg(createHTML()); // send the email email.send(); return errors; }
From source file:org.openhab.binding.mail.internal.MailBuilder.java
/** * Build the Mail/*from w w w .ja va2 s . c o m*/ * * @return instance of Email * @throws EmailException if something goes wrong */ public Email build() throws EmailException { Email mail; if (attachmentURLs.isEmpty() && attachmentFiles.isEmpty() && html.isEmpty()) { // text mail without attachments mail = new SimpleEmail(); if (!text.isEmpty()) { mail.setMsg(text); } } else if (html.isEmpty()) { // text mail with attachments MultiPartEmail multipartMail = new MultiPartEmail(); if (!text.isEmpty()) { multipartMail.setMsg(text); } for (File file : attachmentFiles) { multipartMail.attach(file); } for (URL url : attachmentURLs) { EmailAttachment attachment = new EmailAttachment(); attachment.setURL(url); attachment.setDisposition(EmailAttachment.ATTACHMENT); multipartMail.attach(attachment); } mail = multipartMail; } else { // html email HtmlEmail htmlMail = new HtmlEmail(); if (!text.isEmpty()) { // alternate text supplied htmlMail.setTextMsg(text); htmlMail.setHtmlMsg(html); } else { htmlMail.setMsg(html); } for (File file : attachmentFiles) { htmlMail.attach(new FileDataSource(file), "", ""); } for (URL url : attachmentURLs) { EmailAttachment attachment = new EmailAttachment(); attachment.setURL(url); attachment.setDisposition(EmailAttachment.ATTACHMENT); htmlMail.attach(attachment); } mail = htmlMail; } mail.setTo(recipients); mail.setSubject(subject); if (!sender.isEmpty()) { mail.setFrom(sender); } return mail; }
From source file:org.xmatthew.spy2servers.component.util.EMailUtils.java
/** * <p>/*from ww w . j a v a2 s.c o m*/ * send html body mail * </p> * * @param mailBody * @throws EmailException email about exception */ public static void sendHtmlEmail(MailBody mailBody) throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(mailBody.getLoginServer()); email.setAuthentication(mailBody.getLoginName(), mailBody.getLoginPassword()); //receivers Map<String, String> receivers = mailBody.getReceivers(); parseReceivers(email, receivers); //cc receivers receivers = mailBody.getCcReceivers(); parseCCRecievers(email, receivers); //attatchments Map<String, EmailAttachment> attatchments = mailBody.getAttachments(); parseAttatchments(email, attatchments); String aHtml = mailBody.getAHtml(); if (StringUtils.isNotBlank(aHtml)) { email.setHtmlMsg(aHtml); } email.setFrom(mailBody.getSender(), mailBody.getSender_nick()); email.setSubject(mailBody.getSubject()); email.setMsg(mailBody.getBody()); email.send(); }
From source file:sk.baka.webvm.analyzer.utils.NotificationDelivery.java
/** * Sends a mail with given report.//from ww w .j a v a2s. c o m * @param config the mail server configuration. * @param testing if true then a testing mail is sent * @param reports the current reports * @throws org.apache.commons.mail.EmailException if sending mail fails. */ public static void sendEmail(final Config config, final boolean testing, final List<ProblemReport> reports) throws EmailException { if (!isEmailEnabled(config)) { return; } final HtmlEmail mail = new HtmlEmail(); configure(mail, config); mail.setSubject("WebMon: Problems notification" + (testing ? " (testing mail)" : "")); mail.setMsg(ProblemReport.toString(reports, "\n")); mail.setHtmlMsg("<html><body>\n" + ProblemReport.toHtml(reports) + "\n</body></html>"); mail.send(); }