从Gmail帐户发送Django电子邮件

时间:2017-12-06 04:39:41

标签: python django gmail

在我的settings.py文件中,我有以下内容:

ACCOUNT_EMAIL_VERIFICATION = "none"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "thatotherbatman@gmail.com"
EMAIL_HOST_PASSWORD = "supersecretstring"
EMAIL_PORT = 587
EMAIL_USE_TLS = True

然后我运行python manage.py shell并执行:

from django.conf import settings
from django.core.mail import send_mail

send_mail("foo", "bar", settings.EMAIL_HOST_USER, ["otheruser@gmail.com"])

产生这个:

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

我还在我的Google帐户中启用了安全性较低的应用。我做错了什么?

1 个答案:

答案 0 :(得分:0)

在晚上尝试pip install时遇到同样的错误。重新启动机器,错误就消失了。