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.comDKIM_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
- New Snippet! by Antoliny0919 28 minutes ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 2 months, 2 weeks ago
- get_object_or_none by azwdevops 6 months, 1 week ago
- Mask sensitive data from logger by agusmakmun 8 months ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 10 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.