mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-15 09:24:11 +00:00
Simplify: remove djmail and django-ses-backend dependencies.
This commit is contained in:
parent
1e05de14be
commit
b63f19f415
6 changed files with 51 additions and 23 deletions
24
README.md
24
README.md
|
@ -135,21 +135,17 @@ configuration from environment variables like so:
|
|||
## Sending Emails
|
||||
|
||||
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:
|
||||
links and alerts to users. Put your SMTP server configuration in
|
||||
`hc/local_settings.py` like so:
|
||||
|
||||
DEFAULT_FROM_EMAIL = 'noreply@my-monitoring-project.com'
|
||||
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'
|
||||
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
|
||||
|
||||
|
|
|
@ -9,4 +9,7 @@ class CustomRunner(DiscoverRunner):
|
|||
settings.PASSWORD_HASHERS = \
|
||||
('django.contrib.auth.hashers.MD5PasswordHasher', )
|
||||
|
||||
# Send emails synchronously
|
||||
settings.BLOCKING_EMAILS = True
|
||||
|
||||
super(CustomRunner, self).__init__(*args, **kwargs)
|
||||
|
|
|
@ -1,11 +1,38 @@
|
|||
from threading import Thread
|
||||
|
||||
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):
|
||||
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):
|
||||
|
|
|
@ -23,3 +23,10 @@
|
|||
# '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
|
||||
|
|
|
@ -32,7 +32,6 @@ INSTALLED_APPS = (
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'compressor',
|
||||
'djmail',
|
||||
|
||||
'hc.accounts',
|
||||
'hc.api',
|
||||
|
@ -134,8 +133,6 @@ STATICFILES_FINDERS = (
|
|||
)
|
||||
COMPRESS_OFFLINE = True
|
||||
|
||||
EMAIL_BACKEND = "djmail.backends.default.EmailBackend"
|
||||
|
||||
# Discord integration -- override these in local_settings
|
||||
DISCORD_CLIENT_ID = None
|
||||
DISCORD_CLIENT_SECRET = None
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
croniter
|
||||
django-ses-backend==0.1.1
|
||||
Django==1.10.5
|
||||
django_compressor==2.1
|
||||
djmail==0.11.0
|
||||
psycopg2==2.6.2
|
||||
pytz==2016.7
|
||||
requests==2.9.1
|
||||
|
|
Loading…
Add table
Reference in a new issue