Python Django SMTPAuthenticationError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26697565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:53:28  来源:igfitidea点击:

Django SMTPAuthenticationError

pythondjango

提问by Md. Tanvir Raihan

I am new in django and developing a web application using django. I have successfully set the Signup functionality using Userenain my web application and can Register as a user with Verification Email. I can show you my SMTP settings in my settings.py file

我是 django 的新手,正在使用 django 开发 Web 应用程序。我已经在我的 Web 应用程序中使用Userena成功设置了注册功能,并且可以使用验证电子邮件注册为用户。我可以在我的 settings.py 文件中向你展示我的 SMTP 设置

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_HOST_PASSWORD = '**************'

everything was fine before i have changed my EMAIL_HOST_PASSWORD

在我更改 EMAIL_HOST_PASSWORD 之前一切都很好

Infact, for some reason I have to change the previous password of that SERVER_EMAIL([email protected]). I have already edit the EMAIL_HOST_PASSWORD according to the new SERVER_EMAIL password.

事实上,出于某种原因,我必须更改该 SERVER_EMAIL([email protected]) 的先前密码。我已经根据新的 SERVER_EMAIL 密码编辑了 EMAIL_HOST_PASSWORD。

but now, if I want to register as a new user, I am facing the following error

但是现在,如果我想注册为新用户,则会遇到以下错误

SMTPAuthenticationError at /accounts/signup/
(534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvNq\n5.7.14 S3l1pFXENupDa_SdPphNHrnzeLPUOyf6O0l1s31w7h_UARx11P89AxPeeZ6xBi2KeQRjsw\n5.7.14 nvpxZhPVv771W9ljEDyeWnqpqv3_nakuPo36BEl3IlYj9qVujNB5cm0TYFf9LQAxRjFdda\n5.7.14 xh-y5spA9zIQONDsvRRgN3e0DXoIkgxTO3Mu75IaACi-XlvFtFfPBiQ81gUrBZ_PhZsBmh\n5.7.14 ajsSf-flNEmoSydyOTNdmwdB0__8> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 40sm12125121qgi.47 - gsmtp')

采纳答案by rnevius

A relatively recent change in Google's authentication system means you're going to have to "allow less secure app access" to your Google account, in order for this to work.

Google 的身份验证系统最近发生了一个变化,这意味着您必须“允许安全性较低的应用访问”您的 Google 帐户,才能使其正常工作。

In your error, you are recommended to visit this link: https://support.google.com/mail/answer/78754

在您的错误中,建议您访问此链接:https: //support.google.com/mail/answer/78754

On that page:

在该页面上:

Step #2 asks you to try Displaying an Unlock Captcha

第 2 步要求您尝试显示解锁验证码

Step #3 explains how to allow less secure app access. In summary:

第 3 步解释了如何允许不太安全的应用程序访问。总之:

Go to Allow less secure appsand choose "Allow" to let less secure apps access your Google account. We don't recommend this option because it may make it easier for someone to gain access to your account.

转到允许安全性较低的应用程序并选择“允许”以允许安全性较低的应用程序访问您的 Google 帐户。我们不建议使用此选项,因为它可能会让他人更轻松地访问您的帐户。

回答by DreamInBox

You need turn on support for less secure devices: https://www.google.com/settings/security/lesssecureapps

您需要打开对不太安全的设备的支持:https: //www.google.com/settings/security/lesssecureapps

回答by vinnu

Make sure that you have selected "Turn On" option in Allow less secure apps page (https://www.google.com/settings/security/lesssecureapps). I suggest you to refresh the page once after selecting "Turn On" radio button. The radio button selection should not move "Turn Off"

确保您在允许安全性较低的应用页面 ( https://www.google.com/settings/security/lesssecureapps) 中选择了“打开”选项。我建议您在选择“打开”单选按钮后刷新页面一次。单选按钮选择不应移动“关闭”

Some how it is getting "Turn Off" automatically.

一些它是如何自动“关闭”的。

回答by Nikhil Gupta

I think you need to turn on google less secure apps. Login to your account and go to less secure appsto change your setting. It is not good but you can try your code.

我认为您需要打开谷歌安全性较低的应用程序。登录您的帐户并转到安全性较低的应用程序以更改您的设置。这不好,但你可以试试你的代码。

回答by David

If you already have allowed access to less secure apps and still having problems go to your account >> login and security >> notifications and activity in your devices, and see if there is a device that tried to access and google denied it, allow that access.

如果您已经允许访问安全性较低的应用程序,但仍有问题,请转到您的帐户 >> 登录和安全 >> 设备中的通知和活动,并查看是否有设备尝试访问但谷歌拒绝了它,请允许使用权。

回答by Dantez Layton

This worked for me:

这对我有用:

I first created email_info.pyin the same folder as settings.py:

我首先email_info.py在与以下文件夹相同的文件夹中创建settings.py

from .email_info import *

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'your_pass'
EMAIL_PORT = 587

Then in settings.pyI added:

然后在settings.py我添加:

from .email_info import *

EMAIL_USE_TLS = EMAIL_USE_TLS
EMAIL_HOST = EMAIL_HOST
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
EMAIL_PORT = EMAIL_PORT

And finally in views.py:

最后在views.py

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

send_mail(subject, message, from_email, to_list, fail_silently=Tre)

Here's a YouTube video that explains this process: https://www.youtube.com/watch?v=51mmqf5a0Ss

这是解释此过程的 YouTube 视频:https: //www.youtube.com/watch?v=51mmqf5a0Ss

回答by Pran Kumar Sarkar

Recent security protocol of Google will not allow you to send messages through less secure apps.

谷歌最近的安全协议不允许您通过不太安全的应用程序发送消息。

So the fix is:

所以修复是:

Turn ON less secure apps.

打开不太安全的应用程序。

But only enabling this doesn't seem to work now.Google does not allow apps to send messages using your default gmail password. So to send messages you have to follow these two simple steps:

但是现在只启用它似乎不起作用。Google 不允许应用使用您的默认 gmail 密码发送邮件。因此,要发送消息,您必须遵循以下两个简单步骤:

  1. Turn ON two factor authentication of your gmail account. Link to turn it on.

  2. Then create app password for your gmail account from Google. It will be a 16 digit code. Put it in settings.pyor _credentials.pyby: EMAIL_HOST_PASSWORD = 'sixt eend igit code'Link to know how to set up your application password for email

  1. 开启 Gmail 帐户的双重身份验证。链接以将其打开。

  2. 然后从 Google 为您的 Gmail 帐户创建应用密码。它将是一个 16 位代码。通过以下方式将其放入settings.py_credentials.pyEMAIL_HOST_PASSWORD = 'sixt eend igit code'链接以了解如何为电子邮件设置应用程序密码

And BINGO! Problem will be solved.

还有宾果游戏!问题将得到解决。

Note:App password can only be created if you have enabled 2 factor authentication for your account.

注意:只有在您为帐户启用了 2 因素身份验证后,才能创建应用密码。

回答by Himanshu Poddar

For me, I did turn on the less secure app option even then I was getting SMTP error.This is how I solved it.

对我来说,即使我收到 SMTP 错误,我也确实打开了不太安全的应用程序选项。这就是我解决它的方法。

Go to https://accounts.google.com/DisplayUnlockCaptchaand allow access to your Google account by clicking on continue and then try resetting password again in Django.

转到https://accounts.google.com/DisplayUnlockCaptcha并通过单击继续允许访问您的 Google 帐户,然后再次尝试在 Django 中重置密码。

回答by Azeez Bello

Go to Allow less secure apps and choose "Allow" to let less secure apps access your Google account. Generally it is recommended to Not enable this option as it may make it easier for someone to gain access to your account. https://www.google.com/settings/security/lesssecureapps

转到允许安全性较低的应用程序并选择“允许”以允许安全性较低的应用程序访问您的 Google 帐户。通常建议不要启用此选项,因为它可能会使某人更容易访问您的帐户。 https://www.google.com/settings/security/lesssecureapps

Then hit this link https://accounts.google.com/b/0/DisplayUnlockCaptcha

然后点击这个链接 https://accounts.google.com/b/0/DisplayUnlockCaptcha

回答by Nishkarsh Gupta

In this case, just go to

在这种情况下,只需转到

https://accounts.google.com/DisplayUnlockCaptcha

https://accounts.google.com/DisplayUnlockCaptcha

(Gmail Login Account same as you defined in Django settings).

(与您在 Django 设置中定义的 Gmail 登录帐户相同)。