summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2009-12-06 18:05:04 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2009-12-06 18:05:04 (GMT)
commitbd1094a4a506e7444350c822a700c82dc91d7728 (patch)
tree9fb271365f989ce9f336471618c0101bb8c0645b
parent483056675169a004a221e21036ed8224dbab8d19 (diff)
downloadcpython-bd1094a4a506e7444350c822a700c82dc91d7728.zip
cpython-bd1094a4a506e7444350c822a700c82dc91d7728.tar.gz
cpython-bd1094a4a506e7444350c822a700c82dc91d7728.tar.bz2
logging: Improved support for SMTP over TLS.
-rw-r--r--Lib/logging/handlers.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 49784ec..45b7cf6 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -810,7 +810,7 @@ class SMTPHandler(logging.Handler):
A handler class which sends an SMTP email for each logging event.
"""
def __init__(self, mailhost, fromaddr, toaddrs, subject,
- credentials=None, secure=False):
+ credentials=None, secure=None):
"""
Initialize the handler.
@@ -819,8 +819,11 @@ class SMTPHandler(logging.Handler):
(host, port) tuple format for the mailhost argument. To specify
authentication credentials, supply a (username, password) tuple
for the credentials argument. To specify the use of a secure
- protocol (TLS), pass in True for the secure argument. This will
- only be used when authentication credentials are supplied.
+ protocol (TLS), pass in a tuple for the secure argument. This will
+ only be used when authentication credentials are supplied. The tuple
+ will be either an empty tuple, or a single-value tuple with the name
+ of a keyfile, or a 2-value tuple with the names of the keyfile and
+ certificate file. (This tuple is passed to the `starttls` method).
"""
logging.Handler.__init__(self)
if isinstance(mailhost, tuple):
@@ -888,9 +891,9 @@ class SMTPHandler(logging.Handler):
self.getSubject(record),
formatdate(), msg)
if self.username:
- if self.secure:
+ if self.secure is not None:
smtp.ehlo()
- smtp.starttls()
+ smtp.starttls(*self.secure)
smtp.ehlo()
smtp.login(self.username, self.password)
smtp.sendmail(self.fromaddr, self.toaddrs, msg)