fix email function

pull/5/head
nathaniel smith 2017-01-20 22:53:17 -08:00
parent 7d24178148
commit cecc9deeb4
1 changed files with 7 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import logging
import requests import requests
from django.conf.settings import MAILGUN_URL, MAILGUN_KEY from django.conf import settings
logger = logging.getLogger() logger = logging.getLogger()
@ -11,8 +11,8 @@ FROM='root@tilde.town'
def send_email(to, body, subject='a message from tilde.town', frum=FROM,): def send_email(to, body, subject='a message from tilde.town', frum=FROM,):
"""Sends an email using mailgun. Logs on failure.""" """Sends an email using mailgun. Logs on failure."""
response = requests.post( response = requests.post(
MAILGUN_URL, settings.MAILGUN_URL,
auth=('api', MAILGUN_KEY), auth=('api', settings.MAILGUN_KEY),
data={ data={
'from': frum, 'from': frum,
'to': to, 'to': to,
@ -22,4 +22,7 @@ def send_email(to, body, subject='a message from tilde.town', frum=FROM,):
) )
if response.status_code != 200: if response.status_code != 200:
logger.error('failed to send email "{}" to {}'.format(subject, to)) logger.error('{}: failed to send email "{}" to {}'.format(
response.status_code,
subject,
to))