tags:

views:

349

answers:

5

According to the documentation, if DEBUG is set to False and something is provided under the ADMINS setting, Django will send an email whenever the code raises a 500 status code. I have the email settings filled out properly (as I can use send_mail fine) but whenever I intentionally put up erroneous code I get my 500.html template but no error email is sent. What could cause Django to not do this?

+2  A: 

Make sure your EMAIL_HOST and EMAIL_PORT are set up right in settings.py (these refer to your SMTP server). It might be assuming that you have an SMTP server running on localhost.

To test this locally, run Python's built-in test SMTP server:

python -m smtpd -n -c DebuggingServer localhost:1025

Then set these values in your settings.py

EMAIL_HOST='localhost'
EMAIL_PORT=1025

Trigger a 500 error, and you should see the e-mail appear in the python smtpd terminal window.

Cathal
I see the message, but if I set it back to my email settings it doesn't work
A: 

Try this

# ./manage shell
>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.', '[email protected]',['[email protected]'], fail_silently=False)

With a [email protected] that you actually get email at.

Paul Tarjan
As I said, I already tried that and it works fine.
+3  A: 

My web hosting provider - Webfaction - only allows emails to be sent From an email that has been explicitly created in the administrator panel. Creating one fixed the problem.

I use webfaction and send e-mails from googlemail, so I don't think that was really the problem.
Dominic Rodger
That is, Django error e-mails get sent from googlemail.
Dominic Rodger
it obviously allows you to send emails if you're using google's smtp server, but if you use smtp.webfaction.com as the host then it won't let you unless the email exists. I didn't change anything else and it fixed it so I'm pretty sure that was it.
A: 

While likely not ideal, I have found using Gmail as the SMTP host works just fine. There is a useful guide at nathanostgard.com.

Feel free to post your relevant settings.py sections (including EMAIL_*, SERVER_EMAIL, ADMINS (just take out your real email), MANAGERS, and DEBUG) if you want an extra set of eyes to check for typos!

John Paulett
A: 

Make sure you have DEBUG = False

Tim Babych