Django Email Admins Using Different Outgoing Email Address Posted on 2009-01-06 by Dave Fowler

Socialbrowse is deployed on EC2 using the Django framework. Unfortunately, as we learned the hard way, EC2 has some serious issues with both reverseDNS and email blocklists and is a horrible place to send emails from. For this reason we use AuthSMTP, an email application that will has a much larger success rate for outgoing emails. The one catch to this is that you pay (a small but significant amount) for each email that is sent out.

About 5 days into using AuthSMTP our database went down for 2 minutes and I received 4k error messages from Django! This ate up my monthly AuthSMTP emails instantly and needless to say I was upset :).

To prevent this from happening again, I configured the error messages to be sent using a different email address. Error emails always go to my gmail account, which does not block EC2 emails so I don't have to worry about the success rate and there for there is no need to go through AuthSMTP.

Here's the snippet to change your outgoing error message email address.

  1. Change the mail_admins function in django/core/ to the following.
  1. Edit the EMAIL_HOST_USER and EMAIL_HOST_PASSWORD variables to be your email and password.
  1. Make sure Postfix or some other application that comes with sendmail is installed
  1. Restart your django server

After those steps your error messages will come directly from your server and not go through AuthSMTP as your regular outgoing emails do.

def mail_admins(subject, message, fail_silently=False):
    """Sends a message to the admins, as defined by the ADMINS setting."""
    EMAIL_HOST = '' #'' 
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True

    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
                 settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=connection,