From 2369d561b5d1b027436d8d8e10229cd33a416877 Mon Sep 17 00:00:00 2001 From: Thiago Coutinho Date: Fri, 13 Jun 2014 18:37:12 -0300 Subject: [PATCH] Added the option "smtp-ssl-protocol" to make STARTTLS work on Python 3.3+ Signed-off-by: Thiago Coutinho --- rss2email/config.py | 1 + rss2email/email.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rss2email/config.py b/rss2email/config.py index 40c4c0f..78c4fb1 100644 --- a/rss2email/config.py +++ b/rss2email/config.py @@ -191,6 +191,7 @@ CONFIG['DEFAULT'] = _collections.OrderedDict(( ('smtp-password', 'password'), # password for SMTP AUTH ('smtp-server', 'smtp.yourisp.net:25'), ('smtp-ssl', str(False)), # Connect to the SMTP server using SSL + ('smtp-ssl-protocol', 'SSLv3'), # TLS/SSL version to use on STARTTLS when not using 'smtp-ssl' # IMAP configuration ('imap-auth', str(False)), # set to True to use IMAP auth. ('imap-username', 'username'), # username for IMAP authentication diff --git a/rss2email/email.py b/rss2email/email.py index ef798f7..bee9e03 100644 --- a/rss2email/email.py +++ b/rss2email/email.py @@ -34,6 +34,7 @@ from email.utils import parseaddr as _parseaddr import imaplib as _imaplib import io as _io import smtplib as _smtplib +import ssl as _ssl import subprocess as _subprocess import sys as _sys import time as _time @@ -158,7 +159,13 @@ def smtp_send(sender, recipient, message, config=None, section='DEFAULT'): password = config.get(section, 'smtp-password') try: if not ssl: - smtp.starttls() + protocol_name = config.get(section, 'smtp-ssl-protocol') + protocol = getattr(_ssl, 'PROTOCOL_{}'.format(protocol_name)) + try: + smtp.starttls(context=_ssl.SSLContext(protocol=protocol)) + except TypeError: + # Python 3.2 or earlier + smtp.starttls() smtp.login(username, password) except KeyboardInterrupt: raise -- 2.26.2