Overrides the _send
method of the default SMTP EmailBackend
class to include a DKIM signature based on settings:
DKIM_SELECTOR
-- e.g.'selector'
if usingselector._domainkey.example.com
DKIM_DOMAIN
-- e.g.'example.com'
DKIM_PRIVATE_KEY
-- full private key string, including"""-----BEGIN RSA PRIVATE KEY-----"""
, etc
You'll need pydkim.
Just include this code in project_name.email_backend.py
, for example, and select it in your settings file; e.g. EMAIL_BACKEND = 'project_name.email_backend.DKIMBackend'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from django.core.mail.backends.smtp import EmailBackend
from django.conf import settings
import dkim # http://hewgill.com/pydkim
class DKIMBackend(EmailBackend):
def _send(self, email_message):
"""A helper method that does the actual sending + DKIM signing."""
if not email_message.recipients():
return False
try:
message_string = email_message.message().as_string()
signature = dkim.sign(message_string,
settings.DKIM_SELECTOR,
settings.DKIM_DOMAIN,
settings.DKIM_PRIVATE_KEY)
self.connection.sendmail(email_message.from_email,
email_message.recipients(),
signature+message_string)
except:
if not self.fail_silently:
raise
return False
return True
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 4 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Do you know how this will work with other backends aside from SMTP?
#
DJango version that supports Email_Backend is 1.2 Any idea how to make this work on 1.1?
best!
#
Please login first before commenting.