2017-01-20 08:40:18 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2017-01-21 06:53:17 +00:00
|
|
|
from django.conf import settings
|
2017-01-20 08:40:18 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
FROM='root@tilde.town'
|
|
|
|
|
|
|
|
def send_email(to, body, subject='a message from tilde.town', frum=FROM,):
|
|
|
|
"""Sends an email using mailgun. Logs on failure."""
|
|
|
|
response = requests.post(
|
2017-01-21 06:53:17 +00:00
|
|
|
settings.MAILGUN_URL,
|
|
|
|
auth=('api', settings.MAILGUN_KEY),
|
2017-01-20 08:40:18 +00:00
|
|
|
data={
|
|
|
|
'from': frum,
|
|
|
|
'to': to,
|
|
|
|
'subject': subject,
|
|
|
|
'text': body
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if response.status_code != 200:
|
2017-01-21 06:53:17 +00:00
|
|
|
logger.error('{}: failed to send email "{}" to {}'.format(
|
|
|
|
response.status_code,
|
|
|
|
subject,
|
|
|
|
to))
|