Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django + Heroku + Mandrill mail_admins() not working, either manually or as triggered by 500 error

I have a Django (v1.4) site on Heroku using Mandrill for SMTP. I have all the required values in my settings file:

  • EMAIL_HOST_PASSWORD
  • EMAIL_HOST_USER
  • EMAIL_HOST
  • EMAIL_PORT
  • SERVER_EMAIL (set to a real address, not root@localhost)

I can send regular emails just fine using send_messages() manually from the client. But no emails are sent when for 500 errors and calling mail_admins in the client doesn't produce any errors but also doesn't send an email.

Here is my logging setup:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

And my ADMINS:

ADMINS = (
    ('My Name', '[email protected]'),
)

I've checked my Spam folder and there is nothing there. Am I missing something in settings? Or something else?

like image 783
tchaymore Avatar asked Jun 12 '13 23:06

tchaymore


1 Answers

Have you checked your Mandrill API logs?

I am having the same issue and noticed that the emails are being sent to the Mandrill API (since I set my smtp settings for Mandrill in settings.py), but that the from_email and from_name are empty in the API calls.

So, I found https://github.com/brack3t/Djrill and am about to install it. I'll let you know if it "just works".

EDIT: So after installing djrill and following the documentation I'm getting failed API calls for error messages - the from_email is showing as "root@localhost" for some reason.

When I do the shell test shown on the github page (with an email from an accepted domain for my Mandrill account replacing Djrill Sender), it works:

from django.core.mail import send_mail

send_mail("It works!", "This will get sent through Mandrill",
    "Djrill Sender <[email protected]>", ["[email protected]"])

It turns out that I had my default "From" email setting name confused. Its called SERVER_EMAIL. See https://docs.djangoproject.com/en/1.3/ref/settings/#std:setting-SERVER_EMAIL.

So the following in settings.py fixed my issue:

SERVER_EMAIL = [email protected]
like image 118
kvnn Avatar answered Oct 16 '22 07:10

kvnn