diff --git a/config.py.example b/config.py.example index 41fc0e60f58d25729664b523416732aa327725e4..a51dccb1a7ee24ef52737ef326c9bd821fad7249 100644 --- a/config.py.example +++ b/config.py.example @@ -13,6 +13,7 @@ MAIL_HOST = "mail.example.com:465" MAIL_USER = "user" # set to "" for unauthenticated sending MAIL_PASSWORD = "password" # set to "" for unauthenticated sending MAIL_USE_TLS = True # should match the port in MAIL_HOST (if present there) +MAIL_USE_STARTTLS = False # Usually, it's either this or SMTPS # (local) message queue (necessary) CELERY_BROKER_URL = "redis://localhost:6379/0" diff --git a/utils.py b/utils.py index dfc3fa16cddd7bc6f815caf5701c9b04e63439df..0a3136192d7adcbbfd124bcee2a7772a0829783a 100644 --- a/utils.py +++ b/utils.py @@ -73,6 +73,7 @@ class MailManager: self.username = getattr(config, "MAIL_USER", "") self.password = getattr(config, "MAIL_PASSWORD", "") self.use_tls = getattr(config, "MAIL_USE_TLS", True) + self.use_starttls = getattr(config, "MAIL_USE_STARTTLS", False) def send(self, to_addr, subject, content, appendix=None): if (not self.active @@ -91,6 +92,8 @@ class MailManager: part["Content-Disposition"] = 'attachment; filename="{}"'.format(name) msg.attach(part) server = (smtplib.SMTP_SSL if self.use_tls else smtplib.SMTP)(self.hostname) + if self.use_starttls: + server.starttls() if self.username not in [None, ""] and self.password not in [None, ""]: server.login(self.username, self.password) server.sendmail(self.from_addr, to_addr.split(","), msg.as_string())