Skip to content

Commit

Permalink
Updated MailHandler to allow using TLS without having a keyfile/certfile
Browse files Browse the repository at this point in the history
  • Loading branch information
shanx committed Dec 5, 2011
1 parent 836e390 commit b4a9c7b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions logbook/handlers.py
Expand Up @@ -1021,10 +1021,10 @@ class MailHandler(Handler, StringFormatterHandlerMixin,
record_cache_prune = 0.333

def __init__(self, from_addr, recipients, subject=None,
server_addr=None, credentials=None, secure=None,
record_limit=None, record_delta=None, level=NOTSET,
format_string=None, related_format_string=None,
filter=None, bubble=False):
server_addr=None, credentials=None, use_tls=False,
keyfile=None, certfile=None,record_limit=None,
record_delta=None, level=NOTSET, format_string=None,
related_format_string=None, filter=None, bubble=False):
Handler.__init__(self, level, filter, bubble)
StringFormatterHandlerMixin.__init__(self, format_string)
LimitingHandlerMixin.__init__(self, record_limit, record_delta)
Expand All @@ -1035,7 +1035,9 @@ def __init__(self, from_addr, recipients, subject=None,
self.subject = subject
self.server_addr = server_addr
self.credentials = credentials
self.secure = secure
self.use_tls = use_tls
self.keyfile=keyfile
self.certfile=certfile
if related_format_string is None:
related_format_string = self.default_related_format_string
self.related_format_string = related_format_string
Expand Down Expand Up @@ -1123,15 +1125,15 @@ def get_connection(self):
from smtplib import SMTP, SMTP_PORT, SMTP_SSL_PORT
if self.server_addr is None:
host = 'localhost'
port = self.secure and SMTP_SSL_PORT or SMTP_PORT
port = self.use_tls and SMTP_SSL_PORT or SMTP_PORT
else:
host, port = self.server_addr
con = SMTP()
con.connect(host, port)
if self.credentials is not None:
if self.secure is not None:
if self.use_tls:
con.ehlo()
con.starttls(*self.secure)
con.starttls(self.keyfile, self.certfile)
con.ehlo()
con.login(*self.credentials)
return con
Expand Down

0 comments on commit b4a9c7b

Please sign in to comment.