totally untested email function
parent
756fffa3d8
commit
7d24178148
3
setup.py
3
setup.py
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue