host = new URL(configuration.getServerBaseURL()).getHost();
} catch (MalformedURLException e) {
// ignore
}
SimpleEmail email = new SimpleEmail();
if (StringUtils.isNotBlank(host)) {
/*
* Set headers for proper threading: GMail will not group messages, even if they have same subject, but don't have "In-Reply-To" and
* "References" headers. TODO investigate threading in other clients like KMail, Thunderbird, Outlook
*/
if (StringUtils.isNotEmpty(emailMessage.getMessageId())) {
String messageId = "<" + emailMessage.getMessageId() + "@" + host + ">";
email.addHeader(IN_REPLY_TO_HEADER, messageId);
email.addHeader(REFERENCES_HEADER, messageId);
}
// Set headers for proper filtering
email.addHeader(LIST_ID_HEADER, "SonarQube <sonar." + host + ">");
email.addHeader(LIST_ARCHIVE_HEADER, configuration.getServerBaseURL());
}
// Set general information
email.setCharset("UTF-8");
String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT : emailMessage.getFrom() + " (SonarQube)";
email.setFrom(configuration.getFrom(), from);
email.addTo(emailMessage.getTo(), " ");
String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "")
+ StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
email.setSubject(subject);
email.setMsg(emailMessage.getMessage());
// Send
email.setHostName(configuration.getSmtpHost());
configureSecureConnection(email);
if (StringUtils.isNotBlank(configuration.getSmtpUsername()) || StringUtils.isNotBlank(configuration.getSmtpPassword())) {
email.setAuthentication(configuration.getSmtpUsername(), configuration.getSmtpPassword());
}
email.setSocketConnectionTimeout(SOCKET_TIMEOUT);
email.setSocketTimeout(SOCKET_TIMEOUT);
email.send();
} finally {
Thread.currentThread().setContextClassLoader(classloader);
}
}