]> granicus.if.org Git - python/commitdiff
logging: Improved support for SMTP over TLS.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sun, 6 Dec 2009 18:05:04 +0000 (18:05 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Sun, 6 Dec 2009 18:05:04 +0000 (18:05 +0000)
Lib/logging/handlers.py

index d722e21cf1d6143afa16aee3bfb0b23fb9d44f7a..fb48344f8adcf6b01b0755610902f5031e832a3d 100644 (file)
@@ -804,7 +804,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.
 
@@ -812,9 +812,12 @@ 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.  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.
+        for the credentials argument. To specify the use of a secure
+        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):
@@ -882,9 +885,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)