python - Django 1.8 和 Gmail - SMTPAuthenticationError 用户名和密码不被接受

标签 python django email gmail

我真的不知道我做错了什么。

设置:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3b333f3732013f3a3a2c3b2d2d1e39333f3732703d3133" rel="noreferrer noopener nofollow">[email protected]</a>'
EMAIL_HOST_PASSWORD = '**********'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

python manage.py shell中:

import django
from django.conf import settings
from django.core.mail import send_mail
send_mail('test', 'content', settings.EMAIL_HOST_USER, ['<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e33273b333f37321e39333f3732703d3133" rel="noreferrer noopener nofollow">[email protected]</a>'], fail_silently=False)

我收到以下错误:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python34\lib\site-packages\django\core\mail\__init__.py", line 62, in send_mail
return mail.send()
File "C:\Python34\lib\site-packages\django\core\mail\message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Python34\lib\site-packages\django\core\mail\backends\smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "C:\Python34\lib\site-packages\django\core\mail\backends\smtp.py", line 67, in open
self.connection.login(self.username, self.password)
File "C:\Python34\lib\smtplib.py", line 652, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/answer/14257by17sm25608295wib.18 - gsmtp')

我错过了什么吗?

最佳答案

我自己的错误。我的问题中的上述所有步骤都是正确的。

我运行了from django.conf import settings,更改了文件本身中的用户名/密码详细信息,然后再次导入settings,认为更改将通过之前的导入。他们不是。使用新的 shell 有效!

关于python - Django 1.8 和 Gmail - SMTPAuthenticationError 用户名和密码不被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32094633/

相关文章:

php - 为什么换行符转义序列没有被转换成换行符?

bash - curl : send html email with embedded image and attachment

python - 调用 scipy griddata 时出现类型错误

python - 从文件夹中选择前 n 个最小的文件

python - 为什么 Statsmodels OLS 不支持在包含多个单词的列中阅读?

python - Django rest 框架 - 如何限制对 API 端点的请求?

python - 使用 pip 安装后找不到 cookiecutter 命令

python - django-positions - 使用 parent_link 的多表模型继承

python - Django 在 cookie 中没有 sessionid

python - 解析电子邮件中的 HTML 内容