return Session.getInstance(properties);
}
}
private void sendMail(List<String> toList, List<String> ccList, String subject, String body) {
final SMTPConfiguration smtpConfiguration = maybeSmtpConfiguration.get();
boolean useAuth = false;
if (smtpConfiguration.getUsername().isPresent() && smtpConfiguration.getPassword().isPresent()) {
useAuth = true;
} else if (smtpConfiguration.getUsername().isPresent() || smtpConfiguration.getPassword().isPresent()) {
LOG.warn("Not using smtp authentication because username ({}) or password ({}) was not present", smtpConfiguration.getUsername().isPresent(), smtpConfiguration.getPassword().isPresent());
}
try {
final Session session = createSession(maybeSmtpConfiguration.get(), useAuth);
MimeMessage message = new MimeMessage(session);
Address[] toArray = getAddresses(toList);
message.addRecipients(RecipientType.TO, toArray);
if (!ccList.isEmpty()) {
Address[] ccArray = getAddresses(ccList);
message.addRecipients(RecipientType.CC, ccArray);
}
message.setFrom(new InternetAddress(smtpConfiguration.getFrom()));
message.setSubject(MimeUtility.encodeText(subject, "utf-8", null));
message.setContent(body, "text/html; charset=utf-8");
LOG.trace("Sending a message to {} - {}", Arrays.toString(toArray), getEmailLogFormat(toList, subject));