Skip to content

Instantly share code, notes, and snippets.

@MarkusH
Created September 14, 2014 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkusH/d9944c90346a2defcb99 to your computer and use it in GitHub Desktop.
Save MarkusH/d9944c90346a2defcb99 to your computer and use it in GitHub Desktop.
Django File and Locmem Email Backend
import django
from django.core import mail
from django.core.mail.backends.filebased import EmailBackend as FileEmailBackend
class EmailBackend(FileEmailBackend):
def __init__(self, *args, **kwargs):
super(EmailBackend, self).__init__(*args, **kwargs)
if not hasattr(mail, 'outbox'):
mail.outbox = []
def write_message(self, message):
if django.VERSION[:2] > (1, 5):
super(EmailBackend, self).write_message(message)
mail.outbox.append(message)
def send_messages(self, messages):
ret = super(EmailBackend, self).send_messages(messages)
if django.VERSION[:2] < (1, 6):
mail.outbox.extend(messages)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment