Created
September 14, 2014 23:35
-
-
Save MarkusH/d9944c90346a2defcb99 to your computer and use it in GitHub Desktop.
Django File and Locmem Email Backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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