Simplify: remove djmail and django-ses-backend dependencies.

This commit is contained in:
Pēteris Caune 2017-01-29 11:44:22 +02:00
parent 1e05de14be
commit b63f19f415
6 changed files with 51 additions and 23 deletions

View File

@ -135,21 +135,17 @@ configuration from environment variables like so:
## Sending Emails ## Sending Emails
healthchecks must be able to send email messages, so it can send out login healthchecks must be able to send email messages, so it can send out login
links and alerts to users. You will likely need to tweak email configuration links and alerts to users. Put your SMTP server configuration in
before emails will work. healthchecks uses `hc/local_settings.py` like so:
[djmail](http://bameda.github.io/djmail/) for sending emails asynchronously.
Djmail is a BSD Licensed, simple and nonobstructive django email middleware.
It can be configured to use any regular Django email backend behind the
scenes. For example, the healthchecks.io site uses
[django-ses-backend](https://github.com/piotrbulinski/django-ses-backend/)
and the email configuration in `hc/local_settings.py` looks as follows:
DEFAULT_FROM_EMAIL = 'noreply@my-monitoring-project.com' EMAIL_HOST = "your-smtp-server-here.com"
DJMAIL_REAL_BACKEND = 'django_ses_backend.SESBackend' EMAIL_PORT = 587
AWS_SES_ACCESS_KEY_ID = "put-access-key-here" EMAIL_HOST_USER = "username"
AWS_SES_SECRET_ACCESS_KEY = "put-secret-access-key-here" EMAIL_HOST_PASSWORD = "password"
AWS_SES_REGION_NAME = 'us-east-1' EMAIL_USE_TLS = True
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
For more information, have a look at Django documentation,
[Sending Email](https://docs.djangoproject.com/en/1.10/topics/email/) section.
## Sending Status Notifications ## Sending Status Notifications

View File

@ -9,4 +9,7 @@ class CustomRunner(DiscoverRunner):
settings.PASSWORD_HASHERS = \ settings.PASSWORD_HASHERS = \
('django.contrib.auth.hashers.MD5PasswordHasher', ) ('django.contrib.auth.hashers.MD5PasswordHasher', )
# Send emails synchronously
settings.BLOCKING_EMAILS = True
super(CustomRunner, self).__init__(*args, **kwargs) super(CustomRunner, self).__init__(*args, **kwargs)

View File

@ -1,11 +1,38 @@
from threading import Thread
from django.conf import settings from django.conf import settings
from djmail.template_mail import TemplateMail from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string as render
class EmailThread(Thread):
def __init__(self, name, to, ctx):
Thread.__init__(self)
self.name = name
self.to = to
self.ctx = ctx
def run(self):
self.ctx["SITE_ROOT"] = settings.SITE_ROOT
subject = render('emails/%s-subject.html' % self.name, self.ctx)
subject = subject.strip()
text = render('emails/%s-body-text.html' % self.name, self.ctx)
html = render('emails/%s-body-html.html' % self.name, self.ctx)
msg = EmailMultiAlternatives(subject, text, to=(self.to, ))
msg.attach_alternative(html, "text/html")
msg.send()
def send(name, to, ctx): def send(name, to, ctx):
o = TemplateMail(name) t = EmailThread(name, to, ctx)
ctx["SITE_ROOT"] = settings.SITE_ROOT if hasattr(settings, "BLOCKING_EMAILS"):
o.send(to, ctx) t.run()
else:
t.start()
def login(to, ctx): def login(to, ctx):

View File

@ -23,3 +23,10 @@
# 'TEST': {'CHARSET': 'UTF8'} # 'TEST': {'CHARSET': 'UTF8'}
# } # }
# } # }
# Email
# EMAIL_HOST = "your-smtp-server-here.com"
# EMAIL_PORT = 587
# EMAIL_HOST_USER = "username"
# EMAIL_HOST_PASSWORD = "password"
# EMAIL_USE_TLS = True

View File

@ -32,7 +32,6 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'compressor', 'compressor',
'djmail',
'hc.accounts', 'hc.accounts',
'hc.api', 'hc.api',
@ -134,8 +133,6 @@ STATICFILES_FINDERS = (
) )
COMPRESS_OFFLINE = True COMPRESS_OFFLINE = True
EMAIL_BACKEND = "djmail.backends.default.EmailBackend"
# Discord integration -- override these in local_settings # Discord integration -- override these in local_settings
DISCORD_CLIENT_ID = None DISCORD_CLIENT_ID = None
DISCORD_CLIENT_SECRET = None DISCORD_CLIENT_SECRET = None

View File

@ -1,8 +1,6 @@
croniter croniter
django-ses-backend==0.1.1
Django==1.10.5 Django==1.10.5
django_compressor==2.1 django_compressor==2.1
djmail==0.11.0
psycopg2==2.6.2 psycopg2==2.6.2
pytz==2016.7 pytz==2016.7
requests==2.9.1 requests==2.9.1