SMTPAuthenticationError位于/ password-reset /

时间:2019-04-04 13:15:54

标签: python django

我是Django的新手。我正在尝试在项目中添加一个功能,使用户可以通过给定的电子邮件重设密码。这些配置处于开发阶段,而非生产阶段。这是我在settings.py

中的配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')

我尝试了这些,但似乎没有任何效果。我也通过gmail设置启用了IMAP。 您能帮我在这里做错什么吗! 如果您想看到完整的错误。

  在/ password-reset /处的

SMTPAuthenticationError(535,b'5.7.8用户名和   密码不被接受。

     

https://support.google.com/mail/?p=BadCredentials a24sm3958276ljd.32-   gsmtp')

     

URL:http://localhost:8000/password-reset/   异常类型:SMTPAuthenticationError   b'5.7.8用户名和密码不被接受。在\ n5.7.8了解更多信息   https://support.google.com/mail/?p=BadCredentials a24sm3958276ljd.32-   gsmtp')异常   位置:C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ smtplib.py   在auth中,第642行Python   可执行文件:C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ python.exe   Python版本:3.7.2 Python路径:
  ['C:\ Users \ Administrator \ Desktop \ django_project',   'C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ python37.zip',   'C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ DLLs',   'C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ lib',   'C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37',   'C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python37 \ site-packages',   'C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages']   服务器时间:2019年4月4日,星期四12:24:22 +0000了解更多信息,请参见\ n5.7.8请求方法:POST请求Django版本:2.1.7异常值:(535,

先谢谢您。

3 个答案:

答案 0 :(得分:0)

您介意仔细检查环境变量设置是否正确吗?另外,您是否在您的Google帐户https://www.google.com/settings/security/lesssecureapps上启用了此功能?

看看这个答案,因为它可能也对您有帮助:SMTPAuthenticationError when sending mail using gmail and python

答案 1 :(得分:0)

就我而言,它在我的本地计算机上运行,​​但不在heroku服务器上运行。我点击了此链接https://accounts.google.com/DisplayUnlockCaptcha  并单击继续。之后,我必须重新登录到我的Gmail帐户。它开始工作了。希望它可以帮助某人!

答案 2 :(得分:0)

你需要做两件事来克服非常强大的谷歌的安全性。

  1. 允许安全性较低的应用:开启↓↓↓

    https://myaccount.google.com/lesssecureapps

  2. 允许访问您的 Google 帐户:开启(点按“继续”)↓↓↓

    https://accounts.google.com/DisplayUnlockCaptcha