if (LOG.isTraceEnabled()) {
LOG.trace("sending email to {} with server settings {}",
smtpMessage.getTo(), settings);
}
Email email = new SimpleEmail();
email.setHostName(settings.getSmtpHost());
email.setSmtpPort(settings.getSmtpPort());
email.setFrom(smtpMessage.getFrom().toString());
email.setSubject(smtpMessage.getSubject());
email.setMsg(smtpMessage.getContent());
email.setTo(smtpMessage.getTo());
email.setSentDate(smtpMessage.getDateSent().toDate());
if (settings.getAuthentication() != null) {
email.setAuthentication(settings.getAuthentication().getUserName(),
settings.getAuthentication().getPassword());
}
if (settings.isUseSsl()) {
// enable the use of SSL for SMTP connections. NOTE: should
// only be used for cases when the SMTP server port only supports
// SSL connections (typically over port 465).
email.setSSLOnConnect(true);
} else {
// Support use of the STARTTLS command (see RFC 2487 and RFC 3501)
// to switch the connection to be secured by TLS for cases where the
// server supports both SSL and non-SSL connections. This is
// typically the case for most modern mail servers.
email.setStartTLSEnabled(true);
}
email.setSocketConnectionTimeout(settings.getConnectionTimeout());
email.setSocketTimeout(settings.getSocketTimeout());
email.send();
if (LOG.isTraceEnabled()) {
LOG.trace("email sent to " + smtpMessage.getTo());
}
}