我真的不知道我做错了什么。
设置:
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')
- 我已经尝试过http://www.google.com/accounts/DisplayUnlockCaptcha .
- 我已将其设置为 allow less secure apps access .
- Google 认为该密码是安全的。
- 未启用两步验证。
我错过了什么吗?
最佳答案
我自己的错误。我的问题中的上述所有步骤都是正确的。
我运行了from django.conf import settings
,更改了文件本身中的用户名/密码详细信息,然后再次导入settings
,认为更改将通过之前的导入。他们不是。使用新的 shell 有效!
关于python - Django 1.8 和 Gmail - SMTPAuthenticationError 用户名和密码不被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32094633/