#16 avoid mixing parameters
This commit is contained in:
parent
46de442890
commit
06ac588f74
1 changed files with 8 additions and 6 deletions
14
diffido.py
14
diffido.py
|
@ -295,9 +295,11 @@ def send_email(to, subject='diffido', body='', from_=None):
|
||||||
msg['To'] = to
|
msg['To'] = to
|
||||||
starttls = SMTP_SETTINGS.get('smtp-starttls')
|
starttls = SMTP_SETTINGS.get('smtp-starttls')
|
||||||
use_ssl = SMTP_SETTINGS.get('smtp-use-ssl')
|
use_ssl = SMTP_SETTINGS.get('smtp-use-ssl')
|
||||||
|
username = SMTP_SETTINGS.get('smtp-username')
|
||||||
|
password = SMTP_SETTINGS.get('smtp-password')
|
||||||
args = {}
|
args = {}
|
||||||
for key, value in SMTP_SETTINGS.items():
|
for key, value in SMTP_SETTINGS.items():
|
||||||
if key in ('smtp-starttls', 'smtp-use-ssl'):
|
if key in ('smtp-starttls', 'smtp-use-ssl', 'smtp-username', 'smtp-password'):
|
||||||
continue
|
continue
|
||||||
if key in ('smtp-port'):
|
if key in ('smtp-port'):
|
||||||
value = int(value)
|
value = int(value)
|
||||||
|
@ -306,8 +308,8 @@ def send_email(to, subject='diffido', body='', from_=None):
|
||||||
try:
|
try:
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
with smtplib.SMTP_SSL(**args) as s:
|
with smtplib.SMTP_SSL(**args) as s:
|
||||||
if args.get('username'):
|
if username:
|
||||||
s.login(args.get('username', ''), args.get('password', ''))
|
s.login(username, password)
|
||||||
s.send_message(msg)
|
s.send_message(msg)
|
||||||
else:
|
else:
|
||||||
tls_args = {}
|
tls_args = {}
|
||||||
|
@ -320,7 +322,7 @@ def send_email(to, subject='diffido', body='', from_=None):
|
||||||
s.starttls(**tls_args)
|
s.starttls(**tls_args)
|
||||||
s.ehlo_or_helo_if_needed()
|
s.ehlo_or_helo_if_needed()
|
||||||
if args.get('username'):
|
if args.get('username'):
|
||||||
s.login(args.get('username', ''), args.get('password', ''))
|
s.login(username, password)
|
||||||
s.send_message(msg)
|
s.send_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('unable to send email to %s: %s' % (to, e))
|
logger.error('unable to send email to %s: %s' % (to, e))
|
||||||
|
@ -720,8 +722,8 @@ def serve():
|
||||||
define('smtp-ssl-keyfile', default=None, help='SMTP SSL key file', type=str)
|
define('smtp-ssl-keyfile', default=None, help='SMTP SSL key file', type=str)
|
||||||
define('smtp-ssl-certfile', default=None, help='SMTP SSL cert file', type=str)
|
define('smtp-ssl-certfile', default=None, help='SMTP SSL cert file', type=str)
|
||||||
define('smtp-ssl-context', default=None, help='SMTP SSL context', type=str)
|
define('smtp-ssl-context', default=None, help='SMTP SSL context', type=str)
|
||||||
define('smtp-username', default=None, help='SMTP username', type=str)
|
define('smtp-username', default='', help='SMTP username', type=str)
|
||||||
define('smtp-password', default=None, help='SMTP password', type=str)
|
define('smtp-password', default='', help='SMTP password', type=str)
|
||||||
define('debug', default=False, help='run in debug mode', type=bool)
|
define('debug', default=False, help='run in debug mode', type=bool)
|
||||||
define('config', help='read configuration file',
|
define('config', help='read configuration file',
|
||||||
callback=lambda path: tornado.options.parse_config_file(path, final=False))
|
callback=lambda path: tornado.options.parse_config_file(path, final=False))
|
||||||
|
|
Loading…
Reference in a new issue