commit
1757ec85c8
1
setup.py
1
setup.py
|
@ -18,7 +18,6 @@ setup(
|
||||||
install_requires = ['Django==1.10.2',
|
install_requires = ['Django==1.10.2',
|
||||||
'sshpubkeys==2.2.0',
|
'sshpubkeys==2.2.0',
|
||||||
'psycopg2==2.7.6.1',
|
'psycopg2==2.7.6.1',
|
||||||
'requests==2.12.5',
|
|
||||||
'gunicorn==19.6.0',
|
'gunicorn==19.6.0',
|
||||||
'Mastodon.py==1.1.1',
|
'Mastodon.py==1.1.1',
|
||||||
'tweepy==3.5.0'],
|
'tweepy==3.5.0'],
|
||||||
|
|
|
@ -1,35 +1,26 @@
|
||||||
import logging
|
import logging
|
||||||
|
from smtplib import SMTP_SSL, SMTPException
|
||||||
import requests
|
from email.message import EmailMessage
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
ADMIN_NAME='vilmibm'
|
|
||||||
EXTERNAL_FROM='root@tilde.town'
|
|
||||||
REPLY_TO='tildetown@protonmail.ch'
|
|
||||||
|
|
||||||
def send_email(to, body, subject='a message from tilde.town'):
|
def send_email(to, body, subject='a message from tilde.town'):
|
||||||
"""Sends an email using mailgun. Logs on failure."""
|
"""Sends an email using external SMTP. Logs on failure."""
|
||||||
response = requests.post(
|
em = EmailMessage()
|
||||||
settings.MAILGUN_URL,
|
em['Subject'] = subject
|
||||||
auth=('api', settings.MAILGUN_KEY),
|
em['From'] = 'root@tilde.town'
|
||||||
data={
|
em['To'] = to
|
||||||
'from': EXTERNAL_FROM,
|
em.set_content(body)
|
||||||
'h:Reply-To': REPLY_TO,
|
try:
|
||||||
'to': to,
|
with SMTP_SSL(port=settings.SMTP_PORT, host=settings.SMTP_HOST) as smtp:
|
||||||
'subject': subject,
|
smtp.login('root@tilde.town', settings.SMTP_PASSWORD)
|
||||||
'text': body
|
smtp.send_message(em)
|
||||||
}
|
smtp.quit()
|
||||||
)
|
except SMTPException as e:
|
||||||
|
logger.error(f'failed to send email "{subject}" to {to}: {e}')
|
||||||
|
return False
|
||||||
|
|
||||||
success = response.status_code == 200
|
return True
|
||||||
|
|
||||||
if not success:
|
|
||||||
logger.error('{}: failed to send email "{}" to {}'.format(
|
|
||||||
response.status_code,
|
|
||||||
subject,
|
|
||||||
to))
|
|
||||||
|
|
||||||
return success
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ To run this For Real, you'll want to:
|
||||||
* set a different SECRET_KEY
|
* set a different SECRET_KEY
|
||||||
* change the password for the database or delete the password and use ident
|
* change the password for the database or delete the password and use ident
|
||||||
* change DEBUG to False
|
* change DEBUG to False
|
||||||
* set mailgun api info
|
* set smtp password
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -101,8 +101,9 @@ STATIC_URL = '/static/'
|
||||||
# Not used during local development, but used in staging+live environments
|
# Not used during local development, but used in staging+live environments
|
||||||
STATIC_ROOT = 'static'
|
STATIC_ROOT = 'static'
|
||||||
|
|
||||||
MAILGUN_URL = "OVERWRITE THIS"
|
SMTP_PORT=465
|
||||||
MAILGUN_KEY = "OVERWRITE THIS"
|
SMTP_HOST="smtp.zoho.com"
|
||||||
|
SMTP_PASSWORD="OVERWRITE THIS"
|
||||||
|
|
||||||
# Mastodon credentials
|
# Mastodon credentials
|
||||||
MASTO_CLIENT_ID = "OVERWRITE THIS"
|
MASTO_CLIENT_ID = "OVERWRITE THIS"
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Townie(User):
|
||||||
reasons = TextField(blank=True, null=False, default='')
|
reasons = TextField(blank=True, null=False, default='')
|
||||||
plans = TextField(blank=True, null=False, default='')
|
plans = TextField(blank=True, null=False, default='')
|
||||||
socials = TextField(blank=True, null=False, default='')
|
socials = TextField(blank=True, null=False, default='')
|
||||||
referral = CharField(max_length=100, null=True)
|
referral = CharField(max_length=100, null=True, blank=True)
|
||||||
displayname = CharField(max_length=100, blank=False, null=False)
|
displayname = CharField(max_length=100, blank=False, null=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in New Issue