diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2015-10-17 15:13:10 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2015-10-17 15:13:10 (GMT) |
commit | 277640af0f528f71c9882a30c9325cd02b10a31a (patch) | |
tree | c1c53eaa31c3f6d88d36de8314ac6a5fae97b29d /Lib/logging | |
parent | 4de9dae57dbcac5ac2243e56ad9b13e7a3a9d772 (diff) | |
download | cpython-277640af0f528f71c9882a30c9325cd02b10a31a.zip cpython-277640af0f528f71c9882a30c9325cd02b10a31a.tar.gz cpython-277640af0f528f71c9882a30c9325cd02b10a31a.tar.bz2 |
Closes #25411: Improved Unicode support in SMTPHandler.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/handlers.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index fda8093..13a8fb2 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -1,4 +1,4 @@ -# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2015 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,7 +18,7 @@ Additional handlers for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python. -Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2015 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! """ @@ -965,24 +965,26 @@ class SMTPHandler(logging.Handler): """ try: import smtplib - from email.utils import formatdate + from email.message import EmailMessage + import email.utils + port = self.mailport if not port: port = smtplib.SMTP_PORT smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout) - msg = self.format(record) - msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % ( - self.fromaddr, - ",".join(self.toaddrs), - self.getSubject(record), - formatdate(), msg) + msg = EmailMessage() + msg['From'] = self.fromaddr + msg['To'] = ','.join(self.toaddrs) + msg['Subject'] = self.getSubject(record) + msg['Date'] = email.utils.localtime() + msg.set_content(self.format(record)) if self.username: if self.secure is not None: smtp.ehlo() smtp.starttls(*self.secure) smtp.ehlo() smtp.login(self.username, self.password) - smtp.sendmail(self.fromaddr, self.toaddrs, msg) + smtp.send_message(msg) smtp.quit() except Exception: self.handleError(record) |