简体   繁体   English

Django SMTP错误:身份验证失败:身份验证失败

[英]Django SMTP Error: authentication failed: authentication failure

I set up django email backend following way: 我按照以下方式设置了django电子邮件后端:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

# Host for sending e-mail.
EMAIL_HOST = 'mytdl.de'

# Port for sending e-mail.
EMAIL_PORT = 25

# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = 'me@mytdl.de'
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')

But sending emails with django-allauth will return following error: 但是使用django-allauth发送电子邮件将返回以下错误:

(535, b'5.7.8 Error: authentication failed: authentication failure')

Testing the the settings with 使用测试设置

 telnet  mytdl.de 25

or Thunderbird as email client works fine. 或Thunderbird作为电子邮件客户端工作正常。

2.7.0 Authentication successful

But Django / SMTP stills throws that error. 但是Django / SMTP仍然会引发错误。 Django also tries to Django也试图

AUTH CRAM-MD5

and not 并不是

AUTH LOGIN

any ideas? 有任何想法吗?

If your email host is gmail then you can fix it with these simple steps: 如果您的电子邮件主机是Gmail,那么您可以通过以下简单步骤进行修复:

  1. Login to your gmail account (The one you are using in your Django application for sending mails ). 登录您的Gmail帐户 (您在Django应用程序中用于发送邮件的帐户 )。
  2. Then select Account from google apps or click here . 然后从谷歌应用程序中选择帐户或单击此处
  3. On your control panel click on Apps with account access under Sign-in & security. 在您的控制面板上,单击登录和安全性下的具有帐户访问权限的应用程序
  4. Then scroll down and enable Allow less secure apps 然后向下滚动并启用允许安全性较低的应用

Also maintain your settings variables in this order: 还按此顺序维护设置变量:

settings.py settings.py

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM