Skip to content

Commit

Permalink
fix(mail): make mail configuration entirely optional IQSS#7424
Browse files Browse the repository at this point in the history
Mail notification are optional (mostly to avoid setting up mail
services in dev envs). Do not enforce MTA host config and do not
pester logs about missing configuration.
  • Loading branch information
poikilotherm committed Oct 10, 2023
1 parent e9abfd2 commit 7d1ba87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public Optional<InternetAddress> getSystemAddress() {
logger.log(Level.WARNING, "Could not parse system mail address '%s' provided by %s: "
.formatted(providedByDB ? "DB setting" : "JVM option", mailAddress), e);
} catch (NullPointerException e) {
logger.warning("Could not find a system mail setting in database (key :SystemEmail, deprecated) or JVM option '" + JvmSettings.SYSTEM_EMAIL.getScopedKey() + "'");
// Do not pester the logs - no configuration may mean someone wants to disable mail notifications
logger.fine("Could not find a system mail setting in database (key :SystemEmail, deprecated) or JVM option '" + JvmSettings.SYSTEM_EMAIL.getScopedKey() + "'");
}
// We define the system email address as an optional setting, in case people do not want to enable mail
// notifications (like in a development context, but might be useful elsewhere, too).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class MailSessionProducer {
// classify as spam.
// NOTE: Complete list including descriptions at https://eclipse-ee4j.github.io/angus-mail/docs/api/org.eclipse.angus.mail/org/eclipse/angus/mail/smtp/package-summary.html
static final List<String> smtpStringProps = List.of(
"localhost", "localaddress", "auth.mechanisms", "auth.ntlm.domain", "submitter", "dsn.notify", "dsn.ret",
"host", "localhost", "localaddress", "auth.mechanisms", "auth.ntlm.domain", "submitter", "dsn.notify", "dsn.ret",
"sasl.mechanisms", "sasl.authorizationid", "sasl.realm", "ssl.trust", "ssl.protocols", "ssl.ciphersuites",
"proxy.host", "proxy.port", "proxy.user", "proxy.password", "socks.host", "socks.port", "mailextension"
);
static final List<String> smtpIntProps = List.of(
"port", "connectiontimeout", "timeout", "writetimeout", "localport", "auth.ntlm.flag"
);
static final List<String> smtpBoolProps = List.of(
"ehlo", "auth.login.disable", "auth.plain.disable", "auth.digest-md5.disable", "auth.ntlm.disable",
"auth", "ehlo", "auth.login.disable", "auth.plain.disable", "auth.digest-md5.disable", "auth.ntlm.disable",
"auth.xoauth2.disable", "allow8bitmime", "sendpartial", "sasl.enable", "sasl.usecanonicalhostname",
"quitwait", "quitonsessionreject", "ssl.enable", "ssl.checkserveridentity", "starttls.enable",
"starttls.required", "userset", "noop.strict"
Expand Down Expand Up @@ -90,10 +90,6 @@ Properties getMailProperties() {
// Default = true from microprofile-config.properties as most MTAs these days support SMTPUTF8 extension
configuration.put("mail.mime.allowutf8", JvmSettings.MAIL_MTA_SUPPORT_UTF8.lookup(Boolean.class).toString());

configuration.put(PREFIX + "host", JvmSettings.MAIL_MTA_HOST.lookup());
// default = false from microprofile-config.properties
configuration.put(PREFIX + "auth", JvmSettings.MAIL_MTA_AUTH.lookup(Boolean.class).toString());

// Map properties 1:1 to mail.smtp properties for the mail session.
smtpStringProps.forEach(
prop -> JvmSettings.MAIL_MTA_SETTING.lookupOptional(prop).ifPresent(
Expand Down

0 comments on commit 7d1ba87

Please sign in to comment.