Browse Source

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

pull/114/head
Pēteris Caune 8 years ago
parent
commit
b63f19f415
6 changed files with 52 additions and 24 deletions
  1. +11
    -15
      README.md
  2. +3
    -0
      hc/api/tests/__init__.py
  3. +31
    -4
      hc/lib/emails.py
  4. +7
    -0
      hc/local_settings.py.example
  5. +0
    -3
      hc/settings.py
  6. +0
    -2
      requirements.txt

+ 11
- 15
README.md 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
before emails will work. healthchecks uses
[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 = '[email protected]'
DJMAIL_REAL_BACKEND = 'django_ses_backend.SESBackend'
AWS_SES_ACCESS_KEY_ID = "put-access-key-here"
AWS_SES_SECRET_ACCESS_KEY = "put-secret-access-key-here"
AWS_SES_REGION_NAME = 'us-east-1'
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
links and alerts to users. Put your SMTP server configuration in
`hc/local_settings.py` like so:
EMAIL_HOST = "your-smtp-server-here.com"
EMAIL_PORT = 587
EMAIL_HOST_USER = "username"
EMAIL_HOST_PASSWORD = "password"
EMAIL_USE_TLS = True
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


+ 3
- 0
hc/api/tests/__init__.py 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)

+ 31
- 4
hc/lib/emails.py 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)
ctx["SITE_ROOT"] = settings.SITE_ROOT
o.send(to, ctx)
t = EmailThread(name, to, ctx)
if hasattr(settings, "BLOCKING_EMAILS"):
t.run()
else:
t.start()
def login(to, ctx): def login(to, ctx):


+ 7
- 0
hc/local_settings.py.example 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

+ 0
- 3
hc/settings.py 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


+ 0
- 2
requirements.txt 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

Loading…
Cancel
Save