Email Admins on Errors
A snippet showing how to email admins on errors in Django.
# settings.py (relevant)
ADMINS = [("Ops", "[email protected]")]
SERVER_EMAIL = "[email protected]" # from address
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.example.com"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"mail_admins": {
"class": "django.utils.log.AdminEmailHandler",
"level": "ERROR",
"include_html": True,
},
},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": False,
}
},
}
Explanation:
-
Ensure SMTP is configured and allowed to send from
SERVER_EMAIL. - Any ERRORs from django.request trigger an email to ADMINS with stacktrace and request info.
- Category Logging
- Total Views 629
- Last Modified 21 July, 2026
- Tags #logging #email #admins #errors
Previous snippet
Log to File Example
Next snippet