我想设置一个自动邮件系统,当 Django 应用程序中出现异常时通知管理员用户。现在,我只是想测试一下电子邮件通知系统,并在此处、此处、此处和此处以及其他一些站点上遵循了许多教程和提示。
我正在使用 Python 3.5 和 Django 1.8 的本地 Django 开发环境(不在现场生产场景中)。我在我的家庭网络上(不涉及代理等)
设置.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
。由于某种我不太清楚的原因,电子邮件没有发送。我哪里错了?