diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2015-10-17 15:24:23 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2015-10-17 15:24:23 (GMT) |
commit | 03de71d1365a3f767ab16598ff06091187f44ad7 (patch) | |
tree | 492554f064e370770934fbc9b5c0f00a6fc6ff75 /Lib/logging | |
parent | d469cff021248a1cbfca6080f5daccc092579124 (diff) | |
parent | 3f445f799aeb041cada532be23d835c15a61d432 (diff) | |
download | cpython-03de71d1365a3f767ab16598ff06091187f44ad7.zip cpython-03de71d1365a3f767ab16598ff06091187f44ad7.tar.gz cpython-03de71d1365a3f767ab16598ff06091187f44ad7.tar.bz2 |
Closes #25411: Merged fix from 3.5.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/handlers.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 54bee89..fba04f1 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -974,24 +974,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) |