django - 测试Django电子邮件以进行错误处理报告

标签 django python-3.x error-handling django-email django-errors

我想设置一个自动邮件系统,当Django应用程序中引发异常时通知管理员用户。现在,我只是
我喜欢测试电子邮件通知系统,并且除了其他一些站点之外,还遵循了许多教程和技巧herehere以及herehere

我正在使用Python 3.5和Django 1.8的本地Django开发环境(不在实际生产场景中)。我在我的家庭网络中(不涉及代理等)

settings.py

ADMINS = (
    ('My Name', 'myhotmailaccount@hotmail.com'),
)
#EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
MAILER_LIST = ['myhotmailaccount@hotmail.com']
EMAIL_HOST = 'smtp.live.com'
EMAIL_HOST_USER = 'myhotmailaccount@hotmail.com'
EMAIL_HOST_PASSWORD = 'myhotmail_password'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'noreply@hotmail.com'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'default': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': SITE_ROOT + "/logfile.log",
            'maxBytes': 1024*1024*5, #5 MB
            'backupCount': 5,
            'formatter': 'standard',
        },
        'request_handler':{
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': SITE_ROOT + "/django_request.log",
            'maxBytes': 1024*1024*5, #5 MB
            'backupCount': 2,
            'formatter': 'standard'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        }
    },
    'loggers': {
        '': {
            'handlers':['mail_admins', 'default'],
            'level':'DEBUG',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['request_handler'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django': {
            'handlers': ['request_handler', 'default', 'mail_admins',],
            'propagate': True,
            'level': 'DEBUG',
        },
    }
}

view.py的片段
from django.core.mail import send_mail
from django.core.mail import EmailMessage

def search(request): 
    '''
    other bits of code
    '''     
        send_mail("Subject goes here", "Text goes here", 'noreply@hotmail.com', ['myhotmailaccount@hotmail.com'], fail_silently=True)
        #msg = EmailMessage("Subject goes here", "Text goes here", 'noreply@hotmail.com', ['myhotmailaccount@hotmail.com'])
        #msg.send()
        #return HttpResponse('%s'%res)

问题是:[Errno 60] Operation timed out。由于某些原因(我不太清楚),该电子邮件未发送。我要去哪里错了?

最佳答案

为Hotmail帐户配置了错误的设置,这是我正在测试的。代替:

EMAIL_HOST = 'smtp.live.com' 
EMAIL_PORT = 465

它应该是:
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_PORT = 25

我对这条线进行了周整(尽管没有区别):
send_mail("hi there", "Text goes here", settings.EMAIL_HOST_USER, ['myhotmailaddress@hotmail.com'], fail_silently=True)

关于django - 测试Django电子邮件以进行错误处理报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45755654/

相关文章:

python - 如何计算包含一组列中的值和 Pandas 数据框中另一列中的另一个值的行数?

r - 错误 : [on_request_read] connection reset by peer in R shiny

python - 检查一个范围内的任何日期是否在另一个范围之间

python - CSS 不使用 Apache、Django 和 mod_wsgi 呈现

python - Django:如何在聚合中使用外键字段?

python3 strftime 输出因平台而异

python - PEP 3106 建议更慢的方式?为什么?

Django Url,详细页面的 Slug

ios - Firebase : login error

ios - 我如何才能知道 AdMob 是否加载了广告?