Skip to content

Commit

Permalink
Merge pull request #790 from lucyparsons/fix-signup
Browse files Browse the repository at this point in the history
Fix activation emails, this time for sure
  • Loading branch information
redshiftzero authored Aug 10, 2020
2 parents a372f19 + 922a72d commit fea817f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions OpenOversight/app/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ def send_async_email(app, msg):


def send_email(to, subject, template, **kwargs):
msg = Message(current_app.config['OO_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
sender=current_app.config['OO_MAIL_SENDER'], recipients=[to])
app = current_app._get_current_object()
msg = Message(app.config['OO_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
sender=app.config['OO_MAIL_SENDER'], recipients=[to])
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
# Only send email if we're in prod or staging, otherwise log it so devs can see it
if current_app.env in ("staging", "production"):
thr = Thread(target=send_async_email, args=[current_app, msg])
if app.env in ("staging", "production"):
thr = Thread(target=send_async_email, args=[app, msg])
app.logger.info("Sent email.")
thr.start()
return thr
else:
current_app.logger.info("simulated email:\n%s\n%s", subject, msg.body)
app.logger.info("simulated email:\n%s\n%s", subject, msg.body)

0 comments on commit fea817f

Please sign in to comment.