Skip to content

Instantly share code, notes, and snippets.

@collinanderson
Created February 11, 2016 19:13
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 collinanderson/9fde525ba58c1c9b6c68 to your computer and use it in GitHub Desktop.
Save collinanderson/9fde525ba58c1c9b6c68 to your computer and use it in GitHub Desktop.
from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend as SmtpEmailBackend
class CustomEmailBackend(SmtpEmailBackend):
def _send(self, email_message):
if not email_message.recipients():
return False
message = email_message.message()
try:
message = message.as_bytes()
except AttributeError: # django < 1.6
message = message.as_string()
recipients = ['me@example.com'] if settings.DEBUG else email_message.recipients()
try:
self.connection.sendmail(email_message.from_email, recipients, message)
except:
if not self.fail_silently:
raise
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment