Skip to content

Commit

Permalink
support debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloPhagula committed Jan 13, 2017
1 parent c3f1436 commit 07d52e8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ SMTP_PASSWORD=smtp_password
# Only one should be True
SMTP_USE_TLS=False
SMTP_USE_SSL=True
SMTP_DEBUG=False
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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',
Expand Down

0 comments on commit 07d52e8

Please sign in to comment.