changeset 8752:8bba2d253187

mail: migrate to modern email.message instead of using old compat32 functionality Before, the HTML part could be detected as pure 7-bit and sent as: Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: 7bit Now, it will use: Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable That should work fine too.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 04 Nov 2020 01:20:24 +0100
parents ad239692ea95
children cdcebb7c2900
files kallithea/lib/celerylib/tasks.py
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/celerylib/tasks.py	Wed Nov 04 00:35:21 2020 +0100
+++ b/kallithea/lib/celerylib/tasks.py	Wed Nov 04 01:20:24 2020 +0100
@@ -26,8 +26,7 @@
 :license: GPLv3, see LICENSE.md for more details.
 """
 
-import email.mime.multipart
-import email.mime.text
+import email.message
 import email.utils
 import os
 import smtplib
@@ -310,7 +309,7 @@
         log.warning(logmsg)
         return False
 
-    msg = email.mime.multipart.MIMEMultipart('alternative')
+    msg = email.message.EmailMessage()
     msg['Subject'] = subject
     msg['From'] = app_email_from  # fallback - might be overridden by a header
     msg['To'] = ', '.join(recipients)
@@ -320,8 +319,8 @@
         del msg[key]  # Delete key first to make sure add_header will replace header (if any), no matter the casing
         msg.add_header(key, value)
 
-    msg.attach(email.mime.text.MIMEText(body, 'plain'))
-    msg.attach(email.mime.text.MIMEText(html_body, 'html'))
+    msg.set_content(body)
+    msg.add_alternative(html_body, subtype='html')
 
     try:
         if smtp_use_ssl: