/** * Sends a HTML email using the SMTP configuration in application.conf * * For more information @see <a href="https://commons.apache.org/proper/commons-email/userguide.html">https://commons.apache.org/proper/commons-email/userguide.html</a> * * @param htmlEmail The HTML email to send */ public void send(HtmlEmail htmlEmail) { htmlEmail.setHostName(this.host); htmlEmail.setSmtpPort(this.port); htmlEmail.setAuthenticator(this.defaultAuthenticator); htmlEmail.setSSLOnConnect(this.ssl); try { htmlEmail.send(); } catch (EmailException e) { LOG.error("Failed to send HtmlEmail", e); } } }
private boolean send(String title, String content, List<String> receivers) { try { HtmlEmail email = new HtmlEmail(); email.setAuthentication(Configuration.MAIL_SENDER_USERNAME, Configuration.MAIL_SENDER_PASSWORD); email.setHostName(Configuration.MAIL_SENDER_SMTP_HOST); email.setSmtpPort(Configuration.MAIL_SENDER_SMTP_PORT); email.setFrom(Configuration.MAIL_SENDER_USERNAME, Configuration.MAIL_SENDER_NAME); email.setSubject(title); email.setHtmlMsg(content); email.addTo(receivers.stream().toArray(String[]::new)); email.setCharset("UTF-8"); email.setSSLOnConnect(false); email.send(); logger.info("send mail to {} success", JSON.toJSONString(receivers)); return true; } catch (Exception e) { logger.error("send mail to {} fail, caused by", JSON.toJSONString(receivers), e); return false; } } }
ApacheCommonsEmail(String hostname, int smtpPort, boolean useSsl, boolean useTls, String user, String password, HtmlEmail wrappedEmail) { this.wrappedEmail = wrappedEmail; this.wrappedEmail.setHostName(hostname); this.wrappedEmail.setSmtpPort(smtpPort); this.wrappedEmail.setSSLOnConnect(useSsl); this.wrappedEmail.setStartTLSEnabled(useTls); if (!isNullOrEmpty(user) && !isNullOrEmpty(password)) { this.wrappedEmail.setAuthentication(user, password); } this.wrappedEmail.setDebug(false); }
email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(mailServerUsername, mailServerPassword)); email.setSSLOnConnect(mailServerSSLOnConnect); try { email.addTo(to);
private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException { final HtmlEmail email = new HtmlEmail(); email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled email.setHostName(getSmtpHostname()); email.setSmtpPort(getSmtpPort()); email.setStartTLSRequired(isStartTlsRequired()); email.setSSLOnConnect(isSslOnConnectRequired()); if (isAuthenticationRequired()) { final String username = getSmtpUsername(); LOGGER.debug("Will contact SMTP server as '{}'.", username); email.setAuthentication(getSmtpUsername(), getSmtpPassword()); } else { LOGGER.debug("Will contact SMTP server anonymously."); } email.setFrom(getSender(), session.getName()); email.addTo(getRecipient()); return email; }
private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException { final HtmlEmail email = new HtmlEmail(); email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled email.setHostName(getSmtpHostname()); email.setSmtpPort(getSmtpPort()); email.setStartTLSRequired(isStartTlsRequired()); email.setSSLOnConnect(isSslOnConnectRequired()); if (isAuthenticationRequired()) { final String username = getSmtpUsername(); LOGGER.debug("Will contact SMTP server as '{}'.", username); email.setAuthentication(getSmtpUsername(), getSmtpPassword()); } else { LOGGER.debug("Will contact SMTP server anonymously."); } email.setFrom(getSender(), session.getName()); email.addTo(getRecipient()); return email; }
email.setSSLOnConnect(mailSetting.isEnableSSL()); email.setSSLCheckServerIdentity(false);
private static void initializeEmail(EmailSettings emailSettings) throws EmailException { _logger.info("{}", emailSettings); email = new HtmlEmail(); email.setHostName(emailSettings.getSmtpHost()); email.setSmtpPort(emailSettings.getSmtpPort()); if (emailSettings.getSmtpUsername() != null && emailSettings.getSmtpUsername().length() > 0) { email.setAuthenticator(new DefaultAuthenticator( emailSettings.getSmtpUsername(), emailSettings.getSmtpPassword())); } if (emailSettings.getEnableSsl()) { if (emailSettings.getUseStartTLS()) { email.setStartTLSEnabled(emailSettings.getEnableSsl()); } else { email.setSSLOnConnect(emailSettings.getEnableSsl()); } } email.setFrom(emailSettings.getFromAddress()); }
private static void initializeEmail(EmailSettings emailSettings) throws EmailException { _logger.info("{}", emailSettings); email = new HtmlEmail(); email.setHostName(emailSettings.getSmtpHost()); email.setSmtpPort(emailSettings.getSmtpPort()); if (emailSettings.getSmtpUsername() != null && emailSettings.getSmtpUsername().length() > 0) { email.setAuthenticator(new DefaultAuthenticator( emailSettings.getSmtpUsername(), emailSettings.getSmtpPassword())); } if (emailSettings.getEnableSsl()) { if (emailSettings.getUseStartTLS()) { email.setStartTLSEnabled(emailSettings.getEnableSsl()); } else { email.setSSLOnConnect(emailSettings.getEnableSsl()); } } email.setFrom(emailSettings.getFromAddress()); }