mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2351 (Cannot email when using SSL SMTP server with login)
This commit is contained in:
parent
021149097f
commit
2c4863d7e2
@ -81,7 +81,12 @@ 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
|
||||||
cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
|
class SMTP_SSL(smtplib.SMTP_SSL): # Workaround for bug in smtplib.py
|
||||||
|
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)
|
||||||
@ -93,6 +98,8 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
|
|||||||
s.starttls()
|
s.starttls()
|
||||||
s.ehlo()
|
s.ehlo()
|
||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
|
if encryption == 'SSL':
|
||||||
|
s.sock = s.file.sslobj
|
||||||
s.login(username, password)
|
s.login(username, password)
|
||||||
s.sendmail(from_, to, msg)
|
s.sendmail(from_, to, msg)
|
||||||
return s.quit()
|
return s.quit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user