Django - 使用不同的电子邮件后端管理错误电子邮件 [英] Django - Using a different email backend for admin error emails

查看:577
本文介绍了Django - 使用不同的电子邮件后端管理错误电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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中,引用文档


通过设置AdminEmailHandler的email_backend参数,处理程序正在使用的电子邮件
后端可以被覆盖,如
这样:




$ $ $ $ $ $ $ $ $'$'$'$'$'$'$'$'$' utils.log.AdminEmailHandler',
'email_backend':'django.core.mail.backends.filebased.EmailBackend',
}
},

如果你不想升级(因为1.6不稳定,例如),考虑做一个自定义的e邮件处理程序基于 AdminEmailHandler 。不要那么难,因为这个新功能的实际实现是非常简单和干净的(请参阅pull-request )。



或者,您可以从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:

By setting the email_backend argument of AdminEmailHandler, the email backend that is being used by the handler can be overridden, like this:

'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 - 使用不同的电子邮件后端管理错误电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆