E-mail sending: Allow unencrypted connections to SMTP relay

This commit is contained in:
Kovid Goyal 2010-11-25 09:31:29 -07:00
parent 2df996d408
commit 5825d31ed8
3 changed files with 19 additions and 7 deletions

View File

@ -73,7 +73,7 @@ class SendEmail(QWidget, Ui_Form):
if opts.relay_password:
self.relay_password.setText(unhexlify(opts.relay_password))
self.relay_password.textChanged.connect(self.changed)
(self.relay_tls if opts.encryption == 'TLS' else self.relay_ssl).setChecked(True)
getattr(self, 'relay_'+opts.encryption.lower()).setChecked(True)
self.relay_tls.toggled.connect(self.changed)
for x in ('gmail', 'hotmail'):
@ -210,7 +210,8 @@ class SendEmail(QWidget, Ui_Form):
conf.set('relay_port', self.relay_port.value())
conf.set('relay_username', username if username else None)
conf.set('relay_password', hexlify(password))
conf.set('encryption', 'TLS' if self.relay_tls.isChecked() else 'SSL')
conf.set('encryption', 'TLS' if self.relay_tls.isChecked() else 'SSL'
if self.relay_ssl.isChecked() else 'NONE')
return True

View File

@ -168,7 +168,7 @@
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<item row="4" column="2">
<widget class="QRadioButton" name="relay_ssl">
<property name="toolTip">
<string>Use SSL encryption when connecting to the mail server.</string>
@ -191,6 +191,16 @@
</property>
</spacer>
</item>
<item row="4" column="3">
<widget class="QRadioButton" name="relay_none">
<property name="toolTip">
<string>WARNING: Using no encryption is highly insecure</string>
</property>
<property name="text">
<string>&amp;None</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -90,7 +90,7 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=None,
for x in to:
return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
import calibre.utils.smtplib as smtplib
cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
cls = smtplib.SMTP_SSL if encryption == 'SSL' else smtplib.SMTP
timeout = None # Non-blocking sockets sometimes don't work
port = int(port)
kwargs = dict(timeout=timeout, local_hostname=localhost)
@ -99,7 +99,7 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=None,
s = cls(**kwargs)
s.set_debuglevel(verbose)
if port < 0:
port = 25 if encryption == 'TLS' else 465
port = 25 if encryption != 'SSL' else 465
s.connect(relay, port)
if encryption == 'TLS':
s.starttls()
@ -158,9 +158,9 @@ def option_parser():
r('-u', '--username', help='Username for relay')
r('-p', '--password', help='Password for relay')
r('-e', '--encryption-method', default='TLS',
choices=['TLS', 'SSL'],
choices=['TLS', 'SSL', 'NONE'],
help='Encryption method to use when connecting to relay. Choices are '
'TLS and SSL. Default is TLS.')
'TLS, SSL and NONE. Default is TLS. WARNING: Choosing NONE is highly insecure')
parser.add_option('-o', '--outbox', help='Path to maildir folder to store '
'failed email messages in.')
parser.add_option('-f', '--fork', default=False, action='store_true',
@ -231,6 +231,7 @@ def main(args=sys.argv):
if opts.fork:
if os.fork() != 0:
return 0
try:
sendmail(msg, efrom, eto, localhost=opts.localhost, verbose=opts.verbose,
timeout=opts.timeout, relay=opts.relay, username=opts.username,