问题描述
EMAIL_BACKEND ='djcelery_email我的Django应用程序(CeleryEmailBackend)中使用了自定义邮件后端.backends.CeleryEmailBackend'
我的日志配置:
LOGGING = {
#...
'处理程序':{
'mail_admins':{
'level' ERROR',
'filters':['require_debug_false'],
'class':'django.utils.log.AdminEmailHandler',
},
#...
}
管理员错误电子邮件也会被同一个电子邮件后端发送。
所以如果电子邮件后端有问题(例如芹菜没有运行)。然后我不会收到服务器错误的电子邮件。
有没有办法使 AdminEmailHandler
使用自定义电子邮件后端?
这是可能的,但在django 1.6中,引用:
$ $ $ $ $ $ $ $ $'$'$'$'$'$'$'$'$' utils.log.AdminEmailHandler',
'email_backend':'django.core.mail.backends.filebased.EmailBackend',
}
},
如果你不想升级(因为1.6不稳定,例如),考虑做一个自定义的e邮件处理程序基于。不要那么难,因为这个的实际实现是非常简单和干净的(请参阅)。
或者,您可以从django 1.6中实际提取整个 AdminEmailHandler
类,并将其用作自定义电子邮件处理程序。
I'm using a custom email backend in my Django application (CeleryEmailBackend in this case):
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
My logging configuration:
LOGGING = {
# ...
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
},
# ...
}
The Admin error emails also get sent by the same email backend.
So if there is a problem with the email backend (e.g. Celery is not running). Then I won't receive the server error emails.
Is there a way to make AdminEmailHandler
use a custom email backend?
It's possible, but in django 1.6, quote from documentation:
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'email_backend': 'django.core.mail.backends.filebased.EmailBackend',
}
},
If you don't want to upgrade (since 1.6 is not stable, for example), consider making a custom email handler based on AdminEmailHandler. Should not be hard, because the actual implementation of this new feature is pretty straight-forward and clean (see pull-request).
Or, you can actually extract the whole AdminEmailHandler
class from the django 1.6 and use it as a custom email handler.
这篇关于Django - 使用不同的电子邮件后端管理错误电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!