Reputation: 64901
What's the easiest way to configure Django to send error emails to a special email account?
The docs on error emails don't explicitly mention any way to do this. I know how to write a custom email backend that could lookup and use different credentials, but as the EmailBackend._send method only receives the message, I'm not sure how to detect when the message is in response to a 500 server error.
Upvotes: 2
Views: 254
Reputation: 658
https://stackoverflow.com/a/19001979/483642 It is way easy than below answer. You just need inherit django.core.mail.backends.smtp.EmailBackend
and set email_backend
on your logging config.
Upvotes: 0
Reputation: 43265
You use the logging settings to mail 500 errors to the admin email ids.
Example of a 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,
}
}
}
This will mail all 500 errors in django to the mentioned email ids.
See: Elegant setup of Python logging in Django
and :
https://docs.djangoproject.com/en/dev/topics/logging/#an-example
If you want to use another SMTP server, then use exception middleware .
http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception
in the process_exception
method, you can email the traceback of exception to required
email accounts.
Upvotes: 4