简体   繁体   English

Django Email 发送 SMTP 错误,无法发送邮件

[英]Django Email sending SMTP Error, cant send a mail

I am trying to send email within my Django project:我正在尝试在我的 Django 项目中发送 email :

# settings.py
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
def notify_user(email_address, subject='Subject', message='Some message!') -> None:
    send_mail(
        subject,
        message,
        settings.EMAIL_HOST_USER,
        [email_address],
        fail_silently=False
    )

As I know I need to disable this option ( Gmail Security ), but Gmail don't let me do it.据我所知,我需要禁用此选项( Gmail Security ),但 Gmail 不允许我这样做。

As a result I got this error:结果我得到了这个错误:

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/?p=BadCredentials f14-20020a056512360e00b00492bbf7db8asm320697lfs.85 - gsmtp')

What can I do?我能做些什么? How to disable that option?如何禁用该选项?

Google disabled/discontinued the Less Secure App feature as of May 30th, 2022.自 2022 年 5 月 30 日起,Google 禁用/停止了安全性较低的应用程序功能。

As recommended by @MeL, you could use an alternative but you can still use Gmail to send emails using Django .正如@MeL 推荐的那样,您可以使用替代方案,但您仍然可以使用 Gmail 使用Django发送电子邮件。 You can read this blog Mail setup on django using Gmail to help with guiding the setup if you're unfamiliar with setting up Google App Passwords .如果您不熟悉设置Google App Passwords ,您可以使用 Gmail 在 django 上阅读此博客邮件设置,以帮助指导设置。

In addition to that, you'll need to do one last thing to activate the app password to be used by Django .除此之外,您还需要做最后一件事来激活Django使用的应用程序密码。 You should visit the site https://accounts.google.com/DisplayUnlockCaptcha , select continue and you're all set.您应该访问站点https://accounts.google.com/DisplayUnlockCaptcha , select 继续,一切就绪。

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

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