From 1cbdc56969e3f5350ab96968af4411f0ca0e07e4 Mon Sep 17 00:00:00 2001 From: Alexis M Date: Mon, 30 Sep 2019 17:59:39 +0200 Subject: [PATCH] Fixes email sending. Now works with HTML + alternative plain text + attachments. --- copanier/emails.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/copanier/emails.py b/copanier/emails.py index 3d2d64a..e29f8a3 100644 --- a/copanier/emails.py +++ b/copanier/emails.py @@ -13,10 +13,7 @@ def send(to, subject, body, html=None, copy=None, attachments=None): if not attachments: attachments = [] - msg = MIMEMultipart() - msg.attach(MIMEText(body, "plain")) - if html: - msg.attach(MIMEText(html, "html")) + msg = MIMEMultipart('alternative') msg["Subject"] = subject msg["From"] = config.FROM_EMAIL msg["To"] = to @@ -30,6 +27,11 @@ def send(to, subject, body, html=None, copy=None, attachments=None): filename=file_name) encoders.encode_base64(part) msg.attach(part) + + msg.attach(MIMEText(body, "plain")) + if html: + msg.attach(MIMEText(html, "html")) + if not config.SEND_EMAILS: return print("Sending email", str(body)) try: