From 342314a8347b85a8e6aa9d9f198422daafb93c83 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Sat, 19 Feb 2022 21:02:08 +0100 Subject: [PATCH] SMTP_LOGIN can be set to "", meaning that the smtp server does not want authentication --- copanier/emails.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/copanier/emails.py b/copanier/emails.py index 5aa5bb8..681e243 100644 --- a/copanier/emails.py +++ b/copanier/emails.py @@ -18,16 +18,27 @@ def send(to, subject, body, html=None, copy=None, attachments=None, mail_from=No body = body.replace("https", "http") return print("Sending email", str(body.encode('utf-8')), flush=True) - message.send( - to=to, - mail_from=mail_from, + # if no SMTP_LOGIN specified, don't create user and password fields, as the smtp server don't want them ! + if config.SMTP_LOGIN=="": + smtp={ + "host": config.SMTP_HOST, + "port": "25", + "ssl": False, + } + + else: smtp={ "host": config.SMTP_HOST, "user": config.SMTP_LOGIN, "password": config.SMTP_PASSWORD, - "port": "465", - "ssl": True, - }, + "port": "25", + "ssl": False, + } + + message.send( + to=to, + mail_from=mail_from, + smtp=smtp )