Added TLS parameters to Java Mail Sender (#1666)

* Added TLS parameters to Java Mail Sender

* changelog
This commit is contained in:
Ken Stevens 2020-05-27 19:17:01 -04:00 committed by GitHub
parent cc9f16721f
commit 97a1bd40a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
type: add
issue: 1666
title: "The email sender used by email subscriptions can now be configured with TLS parameters."

View File

@ -41,6 +41,7 @@ import javax.mail.internet.MimeMessage;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim;
@ -53,6 +54,7 @@ public class JavaMailEmailSender implements IEmailSender {
private JavaMailSenderImpl mySender;
private String mySmtpServerUsername;
private String mySmtpServerPassword;
private final Properties myJavaMailProperties = new Properties();
public String getSmtpServerHostname() {
return mySmtpServerHostname;
@ -92,6 +94,38 @@ public class JavaMailEmailSender implements IEmailSender {
mySmtpServerUsername = theSmtpServerUsername;
}
/**
* Set the "mail.smtp.auth" Java Mail Property
*/
public void setAuth(Boolean theAuth) {
myJavaMailProperties.setProperty("mail.smtp.auth", theAuth.toString());
}
/**
* Set the "mail.smtp.starttls.enable" Java Mail Property
*/
public void setStartTlsEnable(Boolean theStartTlsEnable) {
myJavaMailProperties.setProperty("mail.smtp.starttls.enable", theStartTlsEnable.toString());
}
/**
* Set the "mail.smtp.starttls.required" Java Mail Property
*/
public void setStartTlsRequired(Boolean theStartTlsRequired) {
myJavaMailProperties.setProperty("mail.smtp.starttls.required", theStartTlsRequired.toString());
}
/**
* Set the "mail.smtp.quitwait" Java Mail Property
*/
public void setQuitWait(Boolean theQuitWait) {
myJavaMailProperties.setProperty("mail.smtp.quitwait", theQuitWait.toString());
}
@Override
public void send(EmailDetails theDetails) {
String subscriptionId = theDetails.getSubscription().toUnqualifiedVersionless().getValue();
@ -144,6 +178,7 @@ public class JavaMailEmailSender implements IEmailSender {
mySender.setUsername(getSmtpServerUsername());
mySender.setPassword(getSmtpServerPassword());
mySender.setDefaultEncoding(Constants.CHARSET_UTF8.name());
mySender.setJavaMailProperties(myJavaMailProperties);
}
private static String toTrimmedCommaSeparatedString(List<String> theTo) {