From da3425af3f7dac9a5feeff97e75bccb6f2841bdb Mon Sep 17 00:00:00 2001 From: Jurgen S <2502810+thorli@users.noreply.github.com> Date: Fri, 30 Nov 2018 23:57:22 +0100 Subject: [PATCH] #585: proper UTF-8 encoding of email content Updated script so the email content is encoded properly in UTF-8 to avoid "UnicodeEncodeErrors" when non ascii characters are used like german Umlauts etc. --- scripts/EMail.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/EMail.py b/scripts/EMail.py index 2e1241ba..f74b57fb 100755 --- a/scripts/EMail.py +++ b/scripts/EMail.py @@ -93,6 +93,7 @@ import datetime import smtplib from email.mime.text import MIMEText +from email.header import Header try: # python 2 from urllib2 import quote from xmlrpclib import ServerProxy @@ -255,8 +256,9 @@ if (os.environ.get('NZBPO_NZBLOG') == 'Always' or \ text += '\n%s\t%s\t%s' % (entry['Kind'], datetime.datetime.fromtimestamp(int(entry['Time'])), entry['Text']) # Create message -msg = MIMEText(text) -msg['Subject'] = subject +print('[DETAIL] Creating Email') +msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8') +msg['Subject'] = Header(subject, 'utf-8') msg['From'] = os.environ['NZBPO_FROM'] msg['To'] = os.environ['NZBPO_TO'] msg['Date'] = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")