Skip to content

Commit

Permalink
Allow for full TLS/SSL in SMTP connector (Fix #125)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxidorius committed Apr 26, 2019
1 parent a67c5d7 commit e2c8a56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/threepids/medium/email/smtp-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ threepid:
connectors:
smtp:
host: 'smtpHostname'
port: 587
tls: 1 # 0 = no STARTLS, 1 = try, 2 = force
tls: 1 # 0 = no STARTLS, 1 = try, 2 = force, 3 = TLS/SSL
port: 587 # Set appropriate value depending on your TLS setting
login: 'smtpLogin'
password: 'smtpPassword'
```
12 changes: 6 additions & 6 deletions mxisd.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ threepid:
# SMTP host
host: "smtp.example.org"

# SMTP port
port: 587

# STARTLS mode for the connection.
# SSL/TLS is currently not supported. See https://github.com/kamax-matrix/mxisd/issues/125
#
# TLS mode for the connection
# Possible values:
# 0 Disable any kind of TLS entirely
# 1 Enable STARTLS if supported by server (default)
# 2 Force STARTLS and fail if not available
# 3 Use full TLS/SSL instead of STARTLS
#
tls: 1

# SMTP port
# Be sure to adapt depending on your TLS choice, if changed from default
port: 587

# Login for SMTP
login: "matrix-identity@example.org"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public EmailSmtpConnector(EmailSmtpConfig cfg) {
sCfg.setProperty("mail.smtp.auth", "true");
}

if (cfg.getTls() == 3) {
sCfg.setProperty("mail.smtp.ssl.enable", "true");
}

session = Session.getInstance(sCfg);
}

Expand Down Expand Up @@ -101,8 +105,11 @@ public void send(String senderAddress, String senderName, String recipient, Stri

log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
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());
if (StringUtils.isAllEmpty(cfg.getLogin(), cfg.getPassword())) {
Expand Down

0 comments on commit e2c8a56

Please sign in to comment.