Skip to content Skip to sidebar Skip to footer

Receive Django Error Debug Report By Email :

Here is my configuration in django settings : MAILER_LIST = ['toto@toto.com'] EMAIL_HOST = 'toto.smtp.com' EMAIL_HOST_USER = 'toto@toto.com' EMAIL_HOST_PASSWORD = 'tata' EMAIL

Solution 1:

As said in another answers if you want use django build-in AdminEmailHandler, then you need provide ADMINS and MANAGERS instead of MAILER_LIST in your settings.py. Like this:

ADMINS = ['toto@toto.com']  # better to use another mail than EMAIL_HOST_USER
MANAGERS = ADMINS

Django's utils.log have two options for processing your DEBUG value: RequireDebugFalse and RequireDebugTrue.

So if you want send error emails to your admins (ADMINS variable in settings.py) while debug, then you may use similar settings:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue'# log while DEBUG=True
        }
    },
    'handlers': {
        'debug_mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'filters': [require_debug_true],
        }
    },
    'loggers': {
         'django.request': {
             'handlers': ['debug_mail_admins'],
             'level': 'ERROR',
             'propagate': True,
        },
    }
}

Upd.:

Also you can use logging.handlers.SMTPHandler. Then you can write something similar to this code: https://code.djangoproject.com/ticket/15917

Solution 2:

Django handles this for you, you can add

MANAGERS = ['mail@mail.com']

or look into integrating sentry for a more robust error reporting, sentry is free too

Solution 3:

You should use ADMINS:

ADMINS = ['notifications@example.com']

A list of all the people who get code error notifications. When DEBUG=False and AdminEmailHandler is configured in LOGGING (done by default), Django emails these people the details of exceptions raised in the request/response cycle.

More info here

Solution 4:

Other than what has already been said in other answers, do not forget to set SERVER_EMAIL in your settings (docs).

It's the email address that error messages come from; it's similar to DEFAULT_FROM_EMAIL but SERVER_EMAIL is used only for error messages. Default value is 'root@localhost' and if you are using a provider like sendgrid your emails will be blocked.

Post a Comment for "Receive Django Error Debug Report By Email :"