|
1 | | -# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. |
| 1 | +# Copyright 2001-2015 by Vinay Sajip. All Rights Reserved. |
2 | 2 | # |
3 | 3 | # Permission to use, copy, modify, and distribute this software and its |
4 | 4 | # documentation for any purpose and without fee is hereby granted, |
|
18 | 18 | Additional handlers for the logging package for Python. The core package is |
19 | 19 | based on PEP 282 and comments thereto in comp.lang.python. |
20 | 20 |
|
21 | | -Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. |
| 21 | +Copyright (C) 2001-2015 Vinay Sajip. All Rights Reserved. |
22 | 22 |
|
23 | 23 | To use, simply 'import logging.handlers' and log away! |
24 | 24 | """ |
@@ -965,24 +965,26 @@ def emit(self, record): |
965 | 965 | """ |
966 | 966 | try: |
967 | 967 | import smtplib |
968 | | - from email.utils import formatdate |
| 968 | + from email.message import EmailMessage |
| 969 | + import email.utils |
| 970 | + |
969 | 971 | port = self.mailport |
970 | 972 | if not port: |
971 | 973 | port = smtplib.SMTP_PORT |
972 | 974 | smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout) |
973 | | - msg = self.format(record) |
974 | | - msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % ( |
975 | | - self.fromaddr, |
976 | | - ",".join(self.toaddrs), |
977 | | - self.getSubject(record), |
978 | | - formatdate(), msg) |
| 975 | + msg = EmailMessage() |
| 976 | + msg['From'] = self.fromaddr |
| 977 | + msg['To'] = ','.join(self.toaddrs) |
| 978 | + msg['Subject'] = self.getSubject(record) |
| 979 | + msg['Date'] = email.utils.localtime() |
| 980 | + msg.set_content(self.format(record)) |
979 | 981 | if self.username: |
980 | 982 | if self.secure is not None: |
981 | 983 | smtp.ehlo() |
982 | 984 | smtp.starttls(*self.secure) |
983 | 985 | smtp.ehlo() |
984 | 986 | smtp.login(self.username, self.password) |
985 | | - smtp.sendmail(self.fromaddr, self.toaddrs, msg) |
| 987 | + smtp.send_message(msg) |
986 | 988 | smtp.quit() |
987 | 989 | except Exception: |
988 | 990 | self.handleError(record) |
|
0 commit comments