Allow for full TLS/SSL in SMTP connector (Fix #125)

This commit is contained in:
Max Dor
2019-04-26 09:58:46 +02:00
parent a67c5d7ae1
commit e2c8a56135
3 changed files with 17 additions and 10 deletions

View File

@@ -12,8 +12,8 @@ threepid:
connectors: connectors:
smtp: smtp:
host: 'smtpHostname' host: 'smtpHostname'
port: 587 tls: 1 # 0 = no STARTLS, 1 = try, 2 = force, 3 = TLS/SSL
tls: 1 # 0 = no STARTLS, 1 = try, 2 = force port: 587 # Set appropriate value depending on your TLS setting
login: 'smtpLogin' login: 'smtpLogin'
password: 'smtpPassword' password: 'smtpPassword'
``` ```

View File

@@ -91,19 +91,19 @@ threepid:
# SMTP host # SMTP host
host: "smtp.example.org" host: "smtp.example.org"
# SMTP port # TLS mode for the connection
port: 587
# STARTLS mode for the connection.
# SSL/TLS is currently not supported. See https://github.com/kamax-matrix/mxisd/issues/125
#
# Possible values: # Possible values:
# 0 Disable any kind of TLS entirely # 0 Disable any kind of TLS entirely
# 1 Enable STARTLS if supported by server (default) # 1 Enable STARTLS if supported by server (default)
# 2 Force STARTLS and fail if not available # 2 Force STARTLS and fail if not available
# 3 Use full TLS/SSL instead of STARTLS
# #
tls: 1 tls: 1
# SMTP port
# Be sure to adapt depending on your TLS choice, if changed from default
port: 587
# Login for SMTP # Login for SMTP
login: "matrix-identity@example.org" login: "matrix-identity@example.org"

View File

@@ -66,6 +66,10 @@ public class EmailSmtpConnector implements EmailConnector {
sCfg.setProperty("mail.smtp.auth", "true"); sCfg.setProperty("mail.smtp.auth", "true");
} }
if (cfg.getTls() == 3) {
sCfg.setProperty("mail.smtp.ssl.enable", "true");
}
session = Session.getInstance(sCfg); session = Session.getInstance(sCfg);
} }
@@ -101,8 +105,11 @@ public class EmailSmtpConnector implements EmailConnector {
log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort()); log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp"); SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.setStartTLS(cfg.getTls() > 0);
transport.setRequireStartTLS(cfg.getTls() > 1); if (cfg.getTls() < 3) {
transport.setStartTLS(cfg.getTls() > 0);
transport.setRequireStartTLS(cfg.getTls() > 1);
}
log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort()); log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
if (StringUtils.isAllEmpty(cfg.getLogin(), cfg.getPassword())) { if (StringUtils.isAllEmpty(cfg.getLogin(), cfg.getPassword())) {