send_mail在本地工作,但不在生产主机上工作

问题描述 投票:0回答:1

以下工作在本地,但当我将其部署到Digital Ocean的生产主机时,电子邮件不会发送,因为我测试shell命令(python manage.py shell),如下所示。 send_mail线刚刚卡在那里并且收到错误:[Errno 101]网络在几分钟后无法访问。如何捕获电子邮件发送中的错误?请告知我该如何解决此问题。

from django.core.mail import send_mail
send_mail('test email', 'hello world', '[email protected]', ['[email protected]'],fail_silently=False)

# Email settings
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'xxxx' #my gmail password
EMAIL_HOST_USER = '[email protected]' #my gmail username
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
django digital-ocean smtplib django-mailer
1个回答
0
投票

您的Django应用程序设置看起来正确,但您还应该转到https://accounts.google.com/DisplayUnlockCaptcha并确保启用对较低安全性应用程序的访问。 如果你使用双因素身份验证,还要考虑creating an application-specific password

© www.soinside.com 2019 - 2024. All rights reserved.