List of usage examples for org.apache.commons.mail Email setSocketConnectionTimeout
public void setSocketConnectionTimeout(final int socketConnectionTimeout)
From source file:com.turn.sorcerer.util.email.Emailer.java
private void sendEmail() throws EmailException, UnknownHostException { List<String> addresses = Lists .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins())); logger.info("Sending email to {}", addresses.toString()); Email email = new HtmlEmail(); email.setHostName(ADMIN_EMAIL.getHost()); email.setSocketTimeout(30000); // 30 seconds email.setSocketConnectionTimeout(30000); // 30 seconds for (String address : addresses) { email.addTo(address);//from w w w . j a v a2 s . c o m } email.setFrom( SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName()); email.setSubject(title); email.setMsg(body); email.send(); }
From source file:com.mirth.connect.server.util.SMTPConnection.java
public void send(String toList, String ccList, String from, String subject, String body) throws EmailException { Email email = new SimpleEmail(); email.setHostName(host);//from w w w . j a va 2 s . c o m email.setSmtpPort(Integer.parseInt(port)); email.setSocketConnectionTimeout(socketTimeout); email.setDebug(true); if (useAuthentication) { email.setAuthentication(username, password); } if (StringUtils.equalsIgnoreCase(secure, "TLS")) { email.setTLS(true); } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) { email.setSSL(true); } for (String to : StringUtils.split(toList, ",")) { email.addTo(to); } if (StringUtils.isNotEmpty(ccList)) { for (String cc : StringUtils.split(ccList, ",")) { email.addCc(cc); } } email.setFrom(from); email.setSubject(subject); email.setMsg(body); email.send(); }
From source file:com.mirth.connect.server.util.ServerSMTPConnection.java
public void send(String toList, String ccList, String from, String subject, String body, String charset) throws EmailException { Email email = new SimpleEmail(); // Set the charset if it was specified. Otherwise use the system's default. if (StringUtils.isNotBlank(charset)) { email.setCharset(charset);/*w w w . j ava 2 s . c o m*/ } email.setHostName(host); email.setSmtpPort(Integer.parseInt(port)); email.setSocketConnectionTimeout(socketTimeout); email.setDebug(true); if (useAuthentication) { email.setAuthentication(username, password); } if (StringUtils.equalsIgnoreCase(secure, "TLS")) { email.setStartTLSEnabled(true); } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) { email.setSSLOnConnect(true); email.setSslSmtpPort(port); } // These have to be set after the authenticator, so that a new mail session isn't created ConfigurationController configurationController = ControllerFactory.getFactory() .createConfigurationController(); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.protocols", StringUtils.join( MirthSSLUtil.getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()), ' ')); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.ciphersuites", StringUtils.join( MirthSSLUtil.getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()), ' ')); for (String to : StringUtils.split(toList, ",")) { email.addTo(to); } if (StringUtils.isNotEmpty(ccList)) { for (String cc : StringUtils.split(ccList, ",")) { email.addCc(cc); } } email.setFrom(from); email.setSubject(subject); email.setMsg(body); email.send(); }
From source file:com.qwazr.connectors.EmailConnector.java
public void sendEmail(Email email) throws EmailException { email.setHostName(hostname);/*from w w w . j a va 2s . c om*/ if (ssl != null) email.setSSLOnConnect(ssl); if (start_tls_enabled != null) email.setStartTLSEnabled(start_tls_enabled); if (start_tls_required != null) email.setStartTLSRequired(start_tls_required); if (port != null) email.setSmtpPort(port); if (username != null) email.setAuthentication(username, password); if (connection_timeout != null) email.setSocketConnectionTimeout(connection_timeout); if (timeout != null) email.setSocketTimeout(timeout); email.send(); }
From source file:com.qwazr.library.email.EmailConnector.java
public void sendEmail(final Email email) throws EmailException { email.setHostName(hostname);// w w w.ja va 2 s . co m if (ssl != null) email.setSSLOnConnect(ssl); if (start_tls_enabled != null) email.setStartTLSEnabled(start_tls_enabled); if (start_tls_required != null) email.setStartTLSRequired(start_tls_required); if (port != null) email.setSmtpPort(port); if (username != null) email.setAuthentication(username, password); if (connection_timeout != null) email.setSocketConnectionTimeout(connection_timeout); if (timeout != null) email.setSocketTimeout(timeout); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Sends a password reset email to the email address provided * /*from ww w . j a v a 2 s . co m*/ * @param toEmail * @param newPwd * @throws Exception */ public void sendPwdResetMailFromApp(String toEmail, String newPwd) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Reset Olhie Password"); email.setMsg("You have requested that your password be reset. Your new Olhie password is " + newPwd); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Author Request email that goes to the olhie administrator * /*from w w w . j a va2 s .c o m*/ * @param toEmail * @param userId * @param firstName * @param lastName * @param regId * @throws Exception */ public void sendRequestAuthorMailFromApp(String toEmail, String userId, String firstName, String lastName, String regId) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Author Request"); email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Registration Id: " + regId); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * @param toEmail/*from w ww. ja v a 2s.c om*/ * @param userId * @param firstName * @param lastName * @param eventId * @param details * @throws Exception */ public void sendRequestMailForCalendarEventFromApp(String toEmail, String userId, String firstName, String lastName, String eventId, String details) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Calendar Event Request"); email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Event Id: " + eventId + "\n" + details); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.adobe.acs.commons.email.impl.EmailServiceImpl.java
private Email getEmail(final MailTemplate mailTemplate, final Class<? extends Email> mailType, final Map<String, String> params) throws EmailException, MessagingException, IOException { final Email email = mailTemplate.getEmail(StrLookup.mapLookup(params), mailType); if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS) && params.containsKey(EmailServiceConstants.SENDER_NAME)) { email.setFrom(params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS), params.get(EmailServiceConstants.SENDER_NAME)); } else if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)) { email.setFrom(params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS)); }/*from www .ja v a 2s . c om*/ if (connectTimeout > 0) { email.setSocketConnectionTimeout(connectTimeout); } if (soTimeout > 0) { email.setSocketTimeout(soTimeout); } // #1008 setting the subject via the setSubject(..) parameter. if (params.containsKey(EmailServiceConstants.SUBJECT)) { email.setSubject(params.get(EmailServiceConstants.SUBJECT)); } return email; }
From source file:com.mirth.connect.connectors.smtp.SmtpMessageDispatcher.java
@Override public void doDispatch(UMOEvent event) throws Exception { monitoringController.updateStatus(connector, connectorType, Event.BUSY); MessageObject mo = messageObjectController.getMessageObjectFromEvent(event); if (mo == null) { return;/*from w w w. j av a 2s . com*/ } try { Email email = null; if (connector.isHtml()) { email = new HtmlEmail(); } else { email = new MultiPartEmail(); } email.setCharset(connector.getCharsetEncoding()); email.setHostName(replacer.replaceValues(connector.getSmtpHost(), mo)); try { email.setSmtpPort(Integer.parseInt(replacer.replaceValues(connector.getSmtpPort(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } try { email.setSocketConnectionTimeout( Integer.parseInt(replacer.replaceValues(connector.getTimeout(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } if ("SSL".equalsIgnoreCase(connector.getEncryption())) { email.setSSL(true); } else if ("TLS".equalsIgnoreCase(connector.getEncryption())) { email.setTLS(true); } if (connector.isAuthentication()) { email.setAuthentication(replacer.replaceValues(connector.getUsername(), mo), replacer.replaceValues(connector.getPassword(), mo)); } /* * NOTE: There seems to be a bug when calling setTo with a List * (throws a java.lang.ArrayStoreException), so we are using addTo * instead. */ for (String to : replaceValuesAndSplit(connector.getTo(), mo)) { email.addTo(to); } // Currently unused for (String cc : replaceValuesAndSplit(connector.cc(), mo)) { email.addCc(cc); } // Currently unused for (String bcc : replaceValuesAndSplit(connector.getBcc(), mo)) { email.addBcc(bcc); } // Currently unused for (String replyTo : replaceValuesAndSplit(connector.getReplyTo(), mo)) { email.addReplyTo(replyTo); } for (Entry<String, String> header : connector.getHeaders().entrySet()) { email.addHeader(replacer.replaceValues(header.getKey(), mo), replacer.replaceValues(header.getValue(), mo)); } email.setFrom(replacer.replaceValues(connector.getFrom(), mo)); email.setSubject(replacer.replaceValues(connector.getSubject(), mo)); String body = replacer.replaceValues(connector.getBody(), mo); if (connector.isHtml()) { ((HtmlEmail) email).setHtmlMsg(body); } else { email.setMsg(body); } /* * If the MIME type for the attachment is missing, we display a * warning and set the content anyway. If the MIME type is of type * "text" or "application/xml", then we add the content. If it is * anything else, we assume it should be Base64 decoded first. */ for (Attachment attachment : connector.getAttachments()) { String name = replacer.replaceValues(attachment.getName(), mo); String mimeType = replacer.replaceValues(attachment.getMimeType(), mo); String content = replacer.replaceValues(attachment.getContent(), mo); byte[] bytes; if (StringUtils.indexOf(mimeType, "/") < 0) { logger.warn("valid MIME type is missing for email attachment: \"" + name + "\", using default of text/plain"); attachment.setMimeType("text/plain"); bytes = content.getBytes(); } else if ("application/xml".equalsIgnoreCase(mimeType) || StringUtils.startsWith(mimeType, "text/")) { logger.debug("text or XML MIME type detected for attachment \"" + name + "\""); bytes = content.getBytes(); } else { logger.debug("binary MIME type detected for attachment \"" + name + "\", performing Base64 decoding"); bytes = Base64.decodeBase64(content); } ((MultiPartEmail) email).attach(new ByteArrayDataSource(bytes, mimeType), name, null); } /* * From the Commons Email JavaDoc: send returns * "the message id of the underlying MimeMessage". */ String response = email.send(); messageObjectController.setSuccess(mo, response, null); } catch (EmailException e) { alertController.sendAlerts(connector.getChannelId(), Constants.ERROR_402, "Error sending email message.", e); messageObjectController.setError(mo, Constants.ERROR_402, "Error sending email message.", e, null); connector.handleException(new Exception(e)); } finally { monitoringController.updateStatus(connector, connectorType, Event.DONE); } }