Commit 26a2d65c authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Add option to use STARTTLS for mails

/close #147
parent 8c26a9a2
......@@ -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"
......
......@@ -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())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment