Changeset - 8bba2d253187
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2020-11-04 01:20:24
mads@kiilerich.com
Grafted from: 37ba1ca0d7e6
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.
1 file changed with 4 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/celerylib/tasks.py
Show inline comments
 
@@ -23,14 +23,13 @@ Original author and date, and relevant c
 
:created_on: Oct 6, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
: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
 
import time
 
import traceback
 
from collections import OrderedDict
 
@@ -307,24 +306,24 @@ def send_email(recipients, subject, body
 
        log.debug("Sending e-mail. " + logmsg)
 
    else:
 
        log.error("SMTP mail server not configured - cannot send e-mail.")
 
        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)
 
    msg['Date'] = email.utils.formatdate(time.time())
 

	
 
    for key, value in headers.items():
 
        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:
 
            smtp_serv = smtplib.SMTP_SSL(smtp_server, smtp_port)
 
        else:
 
            smtp_serv = smtplib.SMTP(smtp_server, smtp_port)
0 comments (0 inline, 0 general)