From cd3478982c328d84d79c96fc9f8630f9d82689cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Wed, 1 Dec 2021 19:07:24 +0100 Subject: [PATCH] Use the 'NAME' configuration parameter in the email sender name --- canaille/apputils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/canaille/apputils.py b/canaille/apputils.py index 4c49963f..b18fe943 100644 --- a/canaille/apputils.py +++ b/canaille/apputils.py @@ -57,10 +57,19 @@ def send_email(subject, recipient, text, html, sender=None, attachements=None): msg = email.message.EmailMessage() msg.set_content(text) msg.add_alternative(html, subtype="html") + msg["Subject"] = subject - msg["From"] = sender or current_app.config["SMTP"]["FROM_ADDR"] msg["To"] = recipient + if sender: + msg["From"] = sender + elif current_app.config.get("NAME"): + msg["From"] = '"{}" <{}>'.format( + current_app.config.get("NAME"), current_app.config["SMTP"]["FROM_ADDR"] + ) + else: + msg["From"] = current_app.config["SMTP"]["FROM_ADDR"] + attachements = attachements or [] for cid, filename, value in attachements: maintype, subtype = mimetypes.guess_type(filename)[0].split("/")