summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2009-12-06 17:57:11 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2009-12-06 17:57:11 (GMT)
commit483056675169a004a221e21036ed8224dbab8d19 (patch)
treedd1254af38e0523dc5fc953018f862ec712c89a3 /Lib/logging
parent42d63847c32fda10b61c1f420402a09ddbbe95eb (diff)
downloadcpython-483056675169a004a221e21036ed8224dbab8d19.zip
cpython-483056675169a004a221e21036ed8224dbab8d19.tar.gz
cpython-483056675169a004a221e21036ed8224dbab8d19.tar.bz2
logging: Added optional 'secure' parameter to SMTPHandler.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index d752063..49784ec 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -809,7 +809,8 @@ 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):
+ def __init__(self, mailhost, fromaddr, toaddrs, subject,
+ credentials=None, secure=False):
"""
Initialize the handler.
@@ -817,7 +818,9 @@ class SMTPHandler(logging.Handler):
line of the email. To specify a non-standard SMTP port, use the
(host, port) tuple format for the mailhost argument. To specify
authentication credentials, supply a (username, password) tuple
- for the credentials argument.
+ 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.
"""
logging.Handler.__init__(self)
if isinstance(mailhost, tuple):
@@ -833,6 +836,7 @@ class SMTPHandler(logging.Handler):
toaddrs = [toaddrs]
self.toaddrs = toaddrs
self.subject = subject
+ self.secure = secure
def getSubject(self, record):
"""
@@ -884,6 +888,10 @@ class SMTPHandler(logging.Handler):
self.getSubject(record),
formatdate(), msg)
if self.username:
+ if self.secure:
+ smtp.ehlo()
+ smtp.starttls()
+ smtp.ehlo()
smtp.login(self.username, self.password)
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
smtp.quit()