Compare commits
No commits in common. "1ddfb76c859ebd972138a28ea8d0c4856c139c3d" and "678a8bccc52b20d9db668e936dde400ae13bd1ff" have entirely different histories.
1ddfb76c85
...
678a8bccc5
2 changed files with 6 additions and 27 deletions
|
@ -8,5 +8,3 @@ smtp_host='localhost'
|
||||||
#smtp_ssl_keyfile=None
|
#smtp_ssl_keyfile=None
|
||||||
#smtp_ssl_certfile=None
|
#smtp_ssl_certfile=None
|
||||||
#smtp_ssl_context=None
|
#smtp_ssl_context=None
|
||||||
#smtp_username=''
|
|
||||||
#smtp_password=''
|
|
||||||
|
|
31
diffido.py
31
diffido.py
|
@ -23,7 +23,6 @@ import shutil
|
||||||
import urllib
|
import urllib
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.utils import formatdate
|
|
||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
|
@ -294,14 +293,11 @@ def send_email(to, subject='diffido', body='', from_=None):
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
msg['From'] = from_ or EMAIL_FROM
|
msg['From'] = from_ or EMAIL_FROM
|
||||||
msg['To'] = to
|
msg['To'] = to
|
||||||
msg["Date"] = formatdate(localtime=True)
|
|
||||||
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', 'smtp-username', 'smtp-password'):
|
if key in ('smtp-starttls', 'smtp-use-ssl'):
|
||||||
continue
|
continue
|
||||||
if key in ('smtp-port'):
|
if key in ('smtp-port'):
|
||||||
value = int(value)
|
value = int(value)
|
||||||
|
@ -309,31 +305,18 @@ def send_email(to, subject='diffido', body='', from_=None):
|
||||||
args[key] = value
|
args[key] = value
|
||||||
try:
|
try:
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
for key in ('ssl_keyfile', 'ssl_certfile', 'ssl_context'):
|
|
||||||
if key in args:
|
|
||||||
args[key.replace('ssl_', '')] = args[key]
|
|
||||||
del args[key]
|
|
||||||
logger.debug('STMP SSL connection with args: %s' % repr(args))
|
|
||||||
with smtplib.SMTP_SSL(**args) as s:
|
with smtplib.SMTP_SSL(**args) as s:
|
||||||
if username:
|
|
||||||
logger.debug('STMP LOGIN for username %s and password of length %d' % (username, len(password)))
|
|
||||||
s.login(username, password)
|
|
||||||
s.send_message(msg)
|
s.send_message(msg)
|
||||||
else:
|
else:
|
||||||
tls_args = {}
|
tls_args = {}
|
||||||
for key in ('ssl_keyfile', 'ssl_certfile', 'ssl_context'):
|
for key in ('ssl_keyfile', 'ssl_certfile', 'ssl_context'):
|
||||||
if key in args:
|
if key in args:
|
||||||
tls_args[key.replace('ssl_', '')] = args[key]
|
tls_args = args[key]
|
||||||
del args[key]
|
del args[key]
|
||||||
logger.debug('STMP connection with args: %s' % repr(args))
|
|
||||||
with smtplib.SMTP(**args) as s:
|
with smtplib.SMTP(**args) as s:
|
||||||
if starttls:
|
if starttls:
|
||||||
logger.debug('STMP STARTTLS connection with args: %s' % repr(tls_args))
|
|
||||||
s.ehlo_or_helo_if_needed()
|
|
||||||
s.starttls(**tls_args)
|
s.starttls(**tls_args)
|
||||||
if username:
|
s.ehlo_or_helo_if_needed()
|
||||||
logger.debug('STMP LOGIN for username %s and password of length %d' % (username, len(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))
|
||||||
|
@ -730,11 +713,9 @@ def serve():
|
||||||
define('smtp-local-hostname', default=None, help='SMTP local hostname', type=str)
|
define('smtp-local-hostname', default=None, help='SMTP local hostname', type=str)
|
||||||
define('smtp-use-ssl', default=False, help='Use SSL to connect to the SMTP server', type=bool)
|
define('smtp-use-ssl', default=False, help='Use SSL to connect to the SMTP server', type=bool)
|
||||||
define('smtp-starttls', default=False, help='Use STARTTLS to connect to the SMTP server', type=bool)
|
define('smtp-starttls', default=False, help='Use STARTTLS to connect to the SMTP server', type=bool)
|
||||||
define('smtp-ssl-keyfile', default=None, help='SMTP SSL key file', type=str)
|
define('smtp-ssl-keyfile', default=None, help='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='SSL cert file', type=str)
|
||||||
define('smtp-ssl-context', default=None, help='SMTP SSL context', type=str)
|
define('smtp-ssl-context', default=None, help='SSL context', type=str)
|
||||||
define('smtp-username', default='', help='SMTP username', 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