List of usage examples for org.apache.commons.mail HtmlEmail setSSL
@Deprecated public void setSSL(final boolean ssl)
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 w w. j a v a 2 s. c o m*/ 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); }
From source file:org.vulpe.commons.util.VulpeEmailUtil.java
/** * Send Mail to many recipients.//from ww w . ja va 2 s . c o m * * @param recipients * Recipients * @param subject * Subject * @param body * Body * @throws VulpeSystemException * exception */ public static boolean sendMail(final String[] recipients, final String subject, final String body) { boolean sended = true; if (!checkValidEmail(recipients)) { LOG.error("Invalid mails: " + recipients); sended = false; } if (isDebugEnabled) { LOG.debug("Entering in sendMail..."); for (int i = 0; i < recipients.length; i++) { LOG.debug("recipient: " + recipients[i]); } LOG.debug("subject: " + subject); LOG.debug("body: " + body); } try { final ResourceBundle bundle = ResourceBundle.getBundle("mail"); if (bundle != null) { final HtmlEmail mail = new HtmlEmail(); String mailFrom = ""; if (bundle.containsKey("mail.smtp.auth") && Boolean.valueOf(bundle.getString("mail.smtp.auth"))) { final String username = bundle.getString("mail.smtp.user"); final String password = bundle.getString("mail.smtp.password"); mail.setAuthentication(username, password); } if (bundle.containsKey("mail.from")) { mailFrom = bundle.getString("mail.from"); } mail.setFrom(mailFrom); for (final String recipient : recipients) { mail.addTo(recipient); } mail.setHostName(bundle.getString("mail.smtp.host")); final String port = bundle.getString("mail.smtp.port"); mail.setSmtpPort(Integer.valueOf(port)); if (bundle.containsKey("mail.smtp.starttls.enable") && Boolean.valueOf(bundle.getString("mail.smtp.starttls.enable"))) { mail.setTLS(true); mail.setSSL(true); if (bundle.containsKey("mail.smtp.socketFactory.port")) { String factoryPort = bundle.getString("mail.smtp.socketFactory.port"); mail.setSslSmtpPort(factoryPort); } } String encoding = "UTF-8"; if (bundle.containsKey("mail.encode")) { encoding = bundle.getString("mail.encode"); } mail.setCharset(encoding); mail.setSubject(subject); mail.setHtmlMsg(body); mail.send(); } else { LOG.error("Send Mail properties not setted"); sended = false; } } catch (Exception e) { LOG.error("Error on send mail", e); sended = false; } LOG.debug("Out of sendMail..."); return sended; }