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