Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/authed starttls email out #564

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bookie/bcelery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def email_signup_user(email, msg, settings, message_data):
if status == 4:
from bookie.lib.applog import SignupLog
trans = transaction.begin()
SignupLog(SignupLog.ERROR,
SignupLog(email, SignupLog.ERROR,
'Could not send smtp email to signup: ' + email)
trans.commit()

Expand Down
6 changes: 5 additions & 1 deletion bookie/lib/applog.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ def __init__(self, status, message, **kwargs):
class SignupLog(object):
"""Signup Log records."""

def __init__(self, status, message, **kwargs):
ERROR = 0

def __init__(self, user, status, message, **kwargs):
"""A record in the log"""
kwargs['user'] = user
kwargs['status'] = status
kwargs['message'] = message
kwargs['component'] = u'SIGNUPLOG'

# we need to hash down the payload if there is one
if 'payload' in kwargs and kwargs['payload'] is not None:
Expand Down
9 changes: 9 additions & 0 deletions bookie/lib/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,20 @@ def send(self, message_data=None):
try:
all_emails = msg['To']
smtp_server = self.settings.get('email.host')
starttls = self.settings.get('email.starttls', False)
smtp_user = self.settings.get('email.smtp_user', None)
smtp_password = self.settings.get('email.smtp_password', None)

if smtp_server == 'sendmail':
sendmail(msg['To'], msg['From'], msg['Subject'], self.body)
else:
mail_server = smtplib.SMTP(smtp_server)
if starttls:
mail_server.starttls()

if smtp_user is not None and smtp_password is not None:
mail_server.login(smtp_user, smtp_password)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises SMTPAuthenticationError if the credentials are bad, but I couldn't immediately figure out how to log that from here (SignupLog() didn't seem to behave the way I expected).


mail_server.sendmail(msg['From'],
all_emails,
msg.as_string())
Expand Down