summaryrefslogtreecommitdiffstats
path: root/Lib/logging/handlers.py
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)
commit540f21529460a7c289021fb5026b4b8ef5ce8976 (patch)
tree16c710969b8e2025bb568d7aea2ed978abc65836 /Lib/logging/handlers.py
parent8af078fdcac2cbea557137a0d52f3b1eed1a3022 (diff)
downloadcpython-540f21529460a7c289021fb5026b4b8ef5ce8976.zip
cpython-540f21529460a7c289021fb5026b4b8ef5ce8976.tar.gz
cpython-540f21529460a7c289021fb5026b4b8ef5ce8976.tar.bz2
logging: Added optional 'secure' parameter to SMTPHandler.
Diffstat (limited to 'Lib/logging/handlers.py')
-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 2437c34..d722e21 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -803,7 +803,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.
@@ -811,7 +812,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):
@@ -827,6 +830,7 @@ class SMTPHandler(logging.Handler):
toaddrs = [toaddrs]
self.toaddrs = toaddrs
self.subject = subject
+ self.secure = secure
def getSubject(self, record):
"""
@@ -878,6 +882,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()