commit 6c0f63fafcfec8d0d0f076d542737800bfae3ef5
parent 85dbabb11f773c380899435c63d8b3f2867fbbe1
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 28 Apr 2024 17:57:53 +0200
more lenient mail config
Diffstat:
4 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/wimdupont/sxcybot/config/MailConfig.java b/src/main/java/com/wimdupont/sxcybot/config/MailConfig.java
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Configuration;
public class MailConfig {
private boolean enabled;
+ private boolean ssl;
private String from;
private String to;
private String username;
@@ -23,6 +24,14 @@ public class MailConfig {
this.enabled = enabled;
}
+ public boolean isSsl() {
+ return ssl;
+ }
+
+ public void setSsl(boolean ssl) {
+ this.ssl = ssl;
+ }
+
public String getFrom() {
return from;
}
diff --git a/src/main/java/com/wimdupont/sxcybot/services/MailService.java b/src/main/java/com/wimdupont/sxcybot/services/MailService.java
@@ -29,10 +29,7 @@ public class MailService {
if (mailConfig.isEnabled()
&& (mailConfig.getFrom() == null
|| mailConfig.getTo() == null
- || mailConfig.getUsername() == null
- || mailConfig.getPassword() == null
- || mailConfig.getHost() == null
- || mailConfig.getPort() == null)) {
+ || mailConfig.getHost() == null)) {
throw new PropertyNotFoundException("Mail is enabled and required properties are missing.");
}
}
@@ -41,10 +38,12 @@ public class MailService {
public void sendMail(String subject, String body) {
if (mailConfig.isEnabled()) {
var properties = new Properties();
- properties.put("mail.smtp.auth", "true");
- properties.put("mail.smtp.starttls.enable", "true");
+ properties.put("mail.smtp.auth", withAuth());
+ properties.put("mail.smtp.starttls.enable", mailConfig.isSsl());
properties.put("mail.smtp.host", mailConfig.getHost());
- properties.put("mail.smtp.port", mailConfig.getPort());
+ if (mailConfig.getPort() != null) {
+ properties.put("mail.smtp.port", mailConfig.getPort());
+ }
var session = Session.getInstance(properties, getAuthenticator());
try {
@@ -64,6 +63,9 @@ public class MailService {
}
private Authenticator getAuthenticator() {
+ if (!withAuth()) {
+ return null;
+ }
return new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
@@ -72,4 +74,9 @@ public class MailService {
}
};
}
+
+ private boolean withAuth() {
+ return mailConfig.getUsername() != null && mailConfig.getPassword() != null;
+ }
+
}
diff --git a/src/main/java/com/wimdupont/sxcybot/util/ReleaseNotesUtil.java b/src/main/java/com/wimdupont/sxcybot/util/ReleaseNotesUtil.java
@@ -25,7 +25,7 @@ public class ReleaseNotesUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ReleaseNotesUtil.class);
private final ChannelDetailService channelDetailService;
- private static final String GITLAB_URL = "https://gitlab.com/WimDupont/sxcybot";
+ private static final String GITLAB_URL = "https://git.wimdupont.com/sxcybot";
public ReleaseNotesUtil(ChannelDetailService channelDetailService) {
this.channelDetailService = channelDetailService;
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
@@ -29,3 +29,4 @@ mail.enabled=false
#mail.password=
#mail.host=
#mail.port=
+#mail.ssl=