totally untested email function

pull/5/head
nathaniel smith 2017-01-20 00:40:18 -08:00
parent 756fffa3d8
commit 7d24178148
2 changed files with 27 additions and 1 deletions

View File

@ -17,6 +17,7 @@ setup(
packages=['ttadmin'],
install_requires = ['Django==1.10.2',
'sshpubkeys==2.2.0',
'psycopg2==2.6.2',],
'psycopg2==2.6.2',
'requests==2.12.5'],
include_package_data = True,
)

View File

@ -0,0 +1,25 @@
import logging
import requests
from django.conf.settings import MAILGUN_URL, MAILGUN_KEY
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(
MAILGUN_URL,
auth=('api', MAILGUN_KEY),
data={
'from': frum,
'to': to,
'subject': subject,
'text': body
}
)
if response.status_code != 200:
logger.error('failed to send email "{}" to {}'.format(subject, to))