diff --git a/.env.example b/.env.example index 3dac776..0e0ef3c 100644 --- a/.env.example +++ b/.env.example @@ -6,3 +6,4 @@ SMTP_PASSWORD=smtp_password # Only one should be True SMTP_USE_TLS=False SMTP_USE_SSL=True +SMTP_DEBUG=False diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf7ac5..28201d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ For a complete view of all the releases, visit the releases page on GitHub: [https://github.com/dareenzo/send_mail/releases](https://github.com/dareenzo/send_mail/releases) +## v0.3.0 - 2017-01-13 + +- Allow debugging + ## v0.2.0 - 2017-01-13 - Allow connecting to server with SSL diff --git a/send_mail.py b/send_mail.py index f9a77f5..974ec62 100644 --- a/send_mail.py +++ b/send_mail.py @@ -188,6 +188,7 @@ def send_mail(to, subject, message, is_html=False, cc=None, bcc=None, password = kwargs.get('password', None) or os.getenv('SMTP_PASSWORD') use_tls = kwargs.get('use_tls', False) or os.getenv('SMTP_USE_TLS', False) use_ssl = kwargs.get('use_ssl', False) or os.getenv('SMTP_USE_SSL', False) + debug = kwargs.get('debug', False) or os.getenv('SMTP_DEBUG', False) if six.PY2: password = six.binary_type(password) @@ -198,12 +199,21 @@ def send_mail(to, subject, message, is_html=False, cc=None, bcc=None, if use_ssl in ("False", "false"): use_ssl = False + if debug in ("False", "false"): + debug = False + try: # this doesn't support `with` statement so we do `close` the old way. mail_server = smtplib.SMTP_SSL(host, port) if use_ssl else smtplib.SMTP(host, port) + + if debug: + mail_server.set_debuglevel(1) + mail_server.ehlo() + if use_tls: mail_server.starttls() + mail_server.ehlo() mail_server.login(username, password) mail_server.sendmail(subject, list(map(lambda x: x[1], all_destinations)), mail.as_string()) diff --git a/setup.py b/setup.py index c38796b..6c38ef9 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,7 @@ import os import sys import codecs -from email.utils import parseaddr -from setuptools import setup, find_packages +from setuptools import setup if sys.argv[-1] == 'publish': os.system('python setup.py register') @@ -27,7 +26,7 @@ def file_get_contents(filename): setup( name='send_mail', - version='0.2.0', + version='0.3.0', description='Simple email sending module for use in ETL/reporting script.', long_description=LONG_DESCRIPTION, url='https://github.com/dareenzo/send_mail',