List of usage examples for org.apache.commons.mail HtmlEmail setHtmlMsg
public HtmlEmail setHtmlMsg(final String aHtml) throws EmailException
From source file:org.meerkat.network.MailManager.java
/** * testEmailSettingsFromWebService/* w w w.jav a2 s . co m*/ * @param from * @param to * @param smtpServer * @param smtpPort * @param smtpSecurity * @param smtpUser * @param smtpPassword * @return */ public final String sendTestEmailSettingsFromWebService(String from, String to, String smtpServer, String smtpPort, String smtpSecurity, String smtpUser, String smtpPassword) { String resultString = "OK"; HtmlEmail email = new HtmlEmail(); email.setHostName(smtpServer); email.setSmtpPort(Integer.valueOf(smtpPort)); email.setSubject(testSubject); try { email.setHtmlMsg(testMessage); } catch (EmailException e2) { resultString = e2.getMessage(); return resultString; } // SMTP security if (smtpSecurity.equalsIgnoreCase("STARTTLS")) { email.setTLS(true); } else if (smtpSecurity.equalsIgnoreCase("SSLTLS")) { email.setSSL(true); email.setSslSmtpPort(String.valueOf(smtpPort)); } email.setAuthentication(smtpUser, smtpPassword); try { String[] toList = to.split(","); for (int i = 0; i < toList.length; i++) { email.addTo(toList[i].trim()); } } catch (EmailException e1) { resultString = "TO: " + e1.getMessage(); return resultString; } try { email.setFrom(from); } catch (EmailException e1) { resultString = "FROM: " + e1.getMessage(); return resultString; } // Send the email try { email.send(); } catch (EmailException e) { resultString = e.getMessage(); return resultString; } return resultString; }
From source file:org.ms123.common.workflow.tasks.TaskMailExecutor.java
protected HtmlEmail createHtmlEmail(DelegateExecution execution, String text, String html, String attachmentPath) {/* www .j a v a 2 s . c om*/ HtmlEmail email = new HtmlEmail(); try { if (html != null) { email.setHtmlMsg(html); } if (text != null) { // for email clients that don't support html email.setTextMsg(text); } if (attachmentPath != null) { email.attach( createAttachment(new File(getProcessDocBasedir(execution), attachmentPath).toString())); } return email; } catch (EmailException e) { throw new RuntimeException("TaskMailExecutor:Could not create HTML email", e); } }
From source file:org.ms123.common.workflow.TaskSendExecutor.java
protected HtmlEmail createHtmlEmail(DelegateExecution execution, String text, String html, String attachmentPath) {// w w w . j a v a 2 s . co m HtmlEmail email = new HtmlEmail(); try { if (html != null) { email.setHtmlMsg(html); } if (text != null) { // for email clients that don't support html email.setTextMsg(text); } if (attachmentPath != null) { email.attach( createAttachment(new File(getProcessDocBasedir(execution), attachmentPath).toString())); } return email; } catch (EmailException e) { throw new RuntimeException("TaskSendExecutor:Could not create HTML email", e); } }
From source file:org.ng200.openolympus.services.EmailService.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN) public void sendEmail(String emailAddress, String subject, String view, String alternativeText, Map<String, Object> variables) throws MessagingException, EmailException { final Context ctx = new Context(); ctx.setVariables(variables);/*w w w .j a va 2 s. c om*/ final HtmlEmail email = new HtmlEmail(); email.setHostName(this.emailHost); email.setSmtpPort(this.emailHostPort); email.setAuthenticator(new DefaultAuthenticator(this.emailLogin, this.emailPassword)); email.setSSL(true); email.setFrom(this.emailLogin); email.setSubject(subject); final String htmlContent = this.templateEngine.process(view, ctx); email.setHtmlMsg(htmlContent); email.setTextMsg(alternativeText); email.addTo(emailAddress); email.send(); }
From source file:org.onehippo.forge.resetpassword.services.mail.MailServiceImpl.java
@Override public void sendMail(final MailMessage mailMessage) throws EmailException { final HtmlEmail email = new HtmlEmail(); final Session session = getSession(); if (session == null) { throw new EmailException("Unable to send mail; no mail session available"); }// w ww. jav a2 s.c o m email.setMailSession(session); email.addTo(mailMessage.getToMail(), mailMessage.getToName()); email.setFrom(mailMessage.getFromMail(), mailMessage.getFromName()); email.setSubject(mailMessage.getSubject()); // set the html message email.setHtmlMsg(mailMessage.getHtmlTextBody()); // set the alternative message email.setTextMsg(mailMessage.getPlainTextBody()); // send the email email.send(); }
From source file:org.opencron.server.service.NoticeService.java
public void sendMessage(List<User> users, Long workId, String emailAddress, String mobiles, String content) { Log log = new Log(); log.setIsread(false);//from w w w. j a v a2 s . co m log.setAgentId(workId); log.setMessage(content); //??? if (CommonUtils.isEmpty(emailAddress, mobiles)) { log.setType(Opencron.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); return; } /** * ???? */ boolean emailSuccess = false; boolean mobileSuccess = false; Config config = configService.getSysConfig(); try { log.setType(Opencron.MsgType.EMAIL.getValue()); HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName(config.getSmtpHost()); email.setSslSmtpPort(config.getSmtpPort().toString()); email.setAuthentication(config.getSenderEmail(), config.getPassword()); email.setFrom(config.getSenderEmail()); email.setSubject("opencron"); email.setHtmlMsg(msgToHtml(content)); email.addTo(emailAddress.split(",")); email.send(); emailSuccess = true; /** * ?? */ log.setReceiver(emailAddress); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ???? */ try { for (String mobile : mobiles.split(",")) { //??POST String sendUrl = String.format(config.getSendUrl(), mobile, String.format(config.getTemplate(), content)); String url = sendUrl.substring(0, sendUrl.indexOf("?")); String postData = sendUrl.substring(sendUrl.indexOf("?") + 1); String message = HttpUtils.doPost(url, postData, "UTF-8"); log.setResult(message); logger.info(message); mobileSuccess = true; } log.setReceiver(mobiles); log.setType(Opencron.MsgType.SMS.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ??,?? */ if (!mobileSuccess && !emailSuccess) { log.setType(Opencron.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); for (User user : users) { //?? log.setUserId(user.getUserId()); log.setReceiver(user.getUserName()); homeService.saveLog(log); } } }
From source file:org.openhab.binding.mail.internal.MailBuilder.java
/** * Build the Mail/*from w w w . j a 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.oscarehr.oscar_apps.util.Log4JGmailExecutorTask.java
private void sendEmail() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtpServer);/*from ww w.jav a 2 s . c o m*/ if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword); if (smtpSslPort != null) { email.setSSL(true); email.setSslSmtpPort(smtpSslPort); } Session session = email.getMailSession(); Properties properties = session.getProperties(); properties.setProperty("mail.smtp.connectiontimeout", "20000"); properties.setProperty("mail.smtp.timeout", "20000"); email.addTo(recipientEmailAddress, recipientEmailAddress); email.setFrom(smtpUser, smtpUser); email.setSubject(subject); email.setHtmlMsg(contents); email.setTextMsg(contents); email.send(); }
From source file:org.oscarehr.util.EmailUtils.java
/** * This is a convenience method for sending and email to 1 recipient using the configuration file settings. * @throws EmailException /*from w w w .j a v a2s. c o m*/ */ public static void sendEmail(String toEmailAddress, String toName, String fromEmailAddress, String fromName, String subject, String textContents, String htmlContents) throws EmailException { HtmlEmail htmlEmail = getHtmlEmail(); htmlEmail.addTo(toEmailAddress, toName); htmlEmail.setFrom(fromEmailAddress, fromName); htmlEmail.setSubject(subject); if (textContents != null) htmlEmail.setTextMsg(textContents); if (htmlContents != null) htmlEmail.setHtmlMsg(htmlContents); htmlEmail.send(); }
From source file:org.structr.common.MailHelper.java
public static String sendHtmlMail(final String from, final String fromName, final String to, final String toName, final String cc, final String bcc, final String bounce, final String subject, final String htmlContent, final String textContent) throws EmailException { HtmlEmail mail = new HtmlEmail(); setup(mail, to, toName, from, fromName, cc, bcc, bounce, subject); mail.setHtmlMsg(htmlContent); mail.setTextMsg(textContent);//from w ww. ja v a 2s . c om return mail.send(); }