Fix bug in email sending when using an SSL connection

This commit is contained in:
Kovid Goyal 2010-09-01 10:31:53 -06:00
parent d8b578cadb
commit 3c4ab7fb96

View File

@ -81,12 +81,7 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
for x in to: for x in to:
return sendmail_direct(from_, x, msg, timeout, localhost, verbose) return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
import smtplib import smtplib
class SMTP_SSL(smtplib.SMTP_SSL): # Workaround for bug in smtplib.py cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
def _get_socket(self, host, port, timeout):
smtplib.SMTP_SSL._get_socket(self, host, port, timeout)
return self.sock
cls = smtplib.SMTP if encryption == 'TLS' else SMTP_SSL
timeout = None # Non-blocking sockets sometimes don't work timeout = None # Non-blocking sockets sometimes don't work
port = int(port) port = int(port)
s = cls(timeout=timeout, local_hostname=localhost) s = cls(timeout=timeout, local_hostname=localhost)