use of org.apache.commons.mail.resolver.DataSourceClassPathResolver in project estatio by estatio.
the class EmailServiceThrowingException method send.
// endregion
// region > send
@Programmatic
public boolean send(final List<String> toList, final List<String> ccList, final List<String> bccList, final String subject, final String body, final DataSource... attachments) {
try {
final ImageHtmlEmail email = new ImageHtmlEmail();
email.setAuthenticator(new DefaultAuthenticator(senderEmailAddress, senderEmailPassword));
email.setHostName(getSenderEmailHostName());
email.setSmtpPort(senderEmailPort);
email.setStartTLSEnabled(getSenderEmailTlsEnabled());
email.setDataSourceResolver(new DataSourceClassPathResolver("/", true));
//
// change from default impl.
//
email.setSocketTimeout(2000);
email.setSocketConnectionTimeout(2000);
final Properties properties = email.getMailSession().getProperties();
// TODO ISIS-987: check whether all these are required and extract as configuration settings
properties.put("mail.smtps.auth", "true");
properties.put("mail.debug", "true");
properties.put("mail.smtps.port", "" + senderEmailPort);
properties.put("mail.smtps.socketFactory.port", "" + senderEmailPort);
properties.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtps.socketFactory.fallback", "false");
email.setFrom(senderEmailAddress);
email.setSubject(subject);
email.setHtmlMsg(body);
email.setCharset("windows-1252");
if (attachments != null && attachments.length > 0) {
for (DataSource attachment : attachments) {
email.attach(attachment, attachment.getName(), "");
}
}
if (notEmpty(toList)) {
email.addTo(toList.toArray(new String[toList.size()]));
}
if (notEmpty(ccList)) {
email.addCc(ccList.toArray(new String[ccList.size()]));
}
if (notEmpty(bccList)) {
email.addBcc(bccList.toArray(new String[bccList.size()]));
}
email.send();
} catch (EmailException ex) {
//
// change from default impl.
//
LOG.error("An error occurred while trying to send an email about user email verification", ex);
throw new RuntimeException(ex);
}
return true;
}
Aggregations