List of usage examples for org.apache.commons.mail HtmlEmail getMailSession
public Session getMailSession() throws EmailException
From source file:com.zxy.commons.email.MailMessageUtils.java
/** * HtmlEmail// w w w. ja v a 2 s . c o m * * @return HtmlEmail */ @SuppressWarnings("PMD.EmptyCatchBlock") private static HtmlEmail getEmail() { HtmlEmail email = new HtmlEmail(); email.setHostName(SMTP_HOST); email.setSmtpPort(SMTP_PORT); if (StringUtils.isNotBlank(SMTP_USERNAME) && StringUtils.isNotBlank(SMTP_PASSWORD)) { email.setAuthentication(SMTP_USERNAME, SMTP_PASSWORD); } try { Session session = email.getMailSession(); session.getProperties().setProperty("mail.smtp.ehlo", "true"); } catch (EmailException e) { // do nothing } if (StringUtils.isNotBlank(SMTP_MAIL_CHARSET)) { email.setCharset(SMTP_MAIL_CHARSET); } return email; }
From source file:org.oscarehr.oscar_apps.util.Log4JGmailExecutorTask.java
private void sendEmail() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtpServer);/*w ww . j a v a2s.c om*/ 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 method will return an HtmlEmail object populated with * the values passed in, ignoring the parameters in the configuration file. *//*from w ww. j av a2 s. c om*/ public static HtmlEmail getHtmlEmail(String smtpServer, String smtpPort, String smtpUser, String smtpPassword, String connectionSecurity) throws EmailException { logger.debug("smtpServer=" + smtpServer + ", smtpSslPort=" + smtpPort + ", smtpUser=" + smtpUser + ", smtpPassword=" + smtpPassword + ",connectionSecurity=" + connectionSecurity); HtmlEmail email = null; if (RECIPIENT_OVERRIDE_KEY != null || printInsteadOfSend) email = new HtmlEmailWrapper(); else email = new HtmlEmail(); email.setHostName(smtpServer); if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword); Session session = email.getMailSession(); if (connectionSecurity != null) { if (connectionSecurity.equals(CONNECTION_SECURITY_STARTTLS)) { session.getProperties().setProperty(Email.MAIL_TRANSPORT_TLS, "true"); email.setTLS(true); } else if (connectionSecurity.equals(CONNECTION_SECURITY_SSL)) { email.setSSL(true); } } if (smtpPort != null) { email.setSslSmtpPort(smtpPort); } Properties properties = session.getProperties(); properties.setProperty("mail.smtp.connectiontimeout", "20000"); properties.setProperty("mail.smtp.timeout", "20000"); return (email); }