Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add a setting to disable TLS for sending email
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Aug 6, 2021
1 parent 942be23 commit 716eb27
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10546.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a setting to disable TLS when sending email.
8 changes: 8 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,14 @@ email:
#
#require_transport_security: true

# Uncomment the following to disable TLS for SMTP.
#
# By default, if the server supports TLS, it will be used, and the server
# must present a certificate that is valid for 'smtp_host'. If this option
# is set to false, TLS will not be used.
#
#enable_tls: false

# notif_from defines the "From" address to use when sending emails.
# It must be set if email sending is enabled.
#
Expand Down
14 changes: 14 additions & 0 deletions synapse/config/emailconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def read_config(self, config, **kwargs):
self.require_transport_security = email_config.get(
"require_transport_security", False
)
self.enable_smtp_tls = email_config.get("enable_tls", True)
if self.require_transport_security and not self.enable_smtp_tls:
raise ConfigError(
"email.require_transport_security requires email.enable_tls to be true"
)

if "app_name" in email_config:
self.email_app_name = email_config["app_name"]
else:
Expand Down Expand Up @@ -368,6 +374,14 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
#
#require_transport_security: true
# Uncomment the following to disable TLS for SMTP.
#
# By default, if the server supports TLS, it will be used, and the server
# must present a certificate that is valid for 'smtp_host'. If this option
# is set to false, TLS will not be used.
#
#enable_tls: false
# notif_from defines the "From" address to use when sending emails.
# It must be set if email sending is enabled.
#
Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, hs: "HomeServer"):
passwd = hs.config.email.email_smtp_pass
self._smtp_pass = passwd.encode("utf-8") if passwd is not None else None
self._require_transport_security = hs.config.email.require_transport_security
self._enable_tls = hs.config.email.enable_smtp_tls

self._sendmail = _sendmail

Expand Down Expand Up @@ -153,5 +154,5 @@ async def send_email(
password=self._smtp_pass,
require_auth=self._smtp_user is not None,
require_tls=self._require_transport_security,
tls_hostname=self._smtp_host,
tls_hostname=self._smtp_host if self._enable_tls else None,
)

0 comments on commit 716eb27

Please sign in to comment.