简体   繁体   English

使用 Gmail 设置 Django send_mail 后端主机

[英]Set Django send_mail backend host with Gmail

I have been trying search many files to set send_mail backend with Gmail host.我一直在尝试搜索许多文件以使用 Gmail 主机设置 send_mail 后端。 Here is my settings:这是我的设置:

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'myemail'
EMAIL_HOST_PASSWORD = 'mypassword'

DEFAULT_FROM_EMAIL = 'myemail'

It doesn't work...I find someone mentioned to set Gmail Account with "less secure app".它不起作用...我发现有人提到使用“不太安全的应用程序”设置 Gmail 帐户。 So I tried, but it didn't work.所以我尝试了,但没有奏效。 On google website, it says:"To help keep your account secure, from May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password."在谷歌网站上,它说:“为了帮助确保您的帐户安全,从 2022 年 5 月 30 日起,谷歌不再支持使用第三方应用程序或设备要求您仅使用您的用户名登录您的谷歌帐户和密码。” (refer to: https://support.google.com/accounts/answer/6010255?hl=en ). (请参阅: https ://support.google.com/accounts/answer/6010255?hl=en)。

Regardless of all, I still tried to use python3 manage.py shell, and got the error: SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials jj4-20020a170903048400b0016a2b68823esm9889669plb.141 - gsmtp')无论如何,我仍然尝试使用 python3 manage.py shell,并得到错误: SMTPAuthenticationError: (535, b'5.7.8 用户名和密码不被接受。了解更多在\n5.7.8 https://support.google .com/mail/?p=BadCredentials jj4-20020a170903048400b0016a2b68823esm9889669plb.141 - gsmtp')

Could anyone help me, thanks a lot!谁能帮帮我,非常感谢!

I have a similar experience.我也有类似的经历。 When I tested the software, I got the error you mentioned.当我测试软件时,我得到了你提到的错误。 It made me very nervous.这让我非常紧张。

The temporary solution was to change the account password.临时解决方案是更改帐户密码。 Then for some time, I was able to test again using gmail.然后有一段时间,我能够再次使用 gmail 进行测试。 Unfortunately, but after a short time, the access was blocked.不幸的是,但不久之后,访问被阻止了。

I have not found a solution and the previous settings are not available.我还没有找到解决方案,并且之前的设置不可用。 It's a shame that the service makes everything difficult.很遗憾,这项服务使一切变得困难。 You can try free SMTP alternatives.您可以尝试免费的 SMTP 替代方案。

Effective May 30 2022, Google won't let an app login to Gmail with the usual account password.自 2022 年 5 月 30 日起,Google 将不允许应用使用常用帐户密码登录 Gmail。 See: https://support.google.com/accounts/answer/6010255请参阅:https: //support.google.com/accounts/answer/6010255

To work around this you must use a Google "App Password".要解决此问题,您必须使用 Google 的“应用程序密码”。 At myaccount.google.com go to Security, turn on 2FA, then create an App Password.在 myaccount.google.com 转到安全性,打开 2FA,然后创建一个应用密码。

Use the App Password in place of the account password and it will work.使用应用程序密码代替帐户密码,它将起作用。

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

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