mail的Django电子邮件SMTPAuthenticatio

mail的Django电子邮件SMTPAuthenticatio

本文介绍了带有smtp.gmail的Django电子邮件SMTPAuthenticationError 534需要特定于应用程序的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让django发送电子邮件,但出现此错误:

I am trying to have django send emails but I am getting this error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/Library/Python/2.7/site-packages/django/core/mail/message.py", line 286, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
    new_conn_created = self.open()
  File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py", line 59, in open
    self.connection.login(self.username, self.password)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 615, in login
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.9 Application-specific password required. Learn more at\n5.7.9 http://support.google.com/accounts/bin/answer.py?answer=185833 v14sm3323298pbs.11 - gsmtp')

该链接建议我执行两步验证,但我仍然没有结果。

The link suggested my to perform a 2-step verification which I did but still no results.

在我的设置中。py

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

我尝试在Django shell中对此进行测试,但得到了上面显示的错误:

I tried testing this in django shell but got the error shown above:

>>> from django.core.mail import send_mail
>>> from django.conf import settings
>>> sub = "sup man"
>>> msg = "char lisss"
>>> from_user = settings.EMAIL_HOST_USER
>>> to = ["[email protected]"]
>>> send_mail(sub,msg,from_user,to, fail_silently=False)


推荐答案

由于使用2因子身份验证,因此您必须为此应用创建密码,才能在没有2因子身份验证的情况下访问您的Google帐户。

Because you use 2 factor authentication, you must create a password for this application to access your Google account without the 2 factor auth.

执行Google支持页面上的所有步骤以生成应用程序密码,然后更新您的EMAIL_HOST_PASSWORD以使用该密码,而不是常规的帐户密码。

Perform all the steps on the Google support page to generate an application password, and then update your EMAIL_HOST_PASSWORD to use that, rather than your regular account password.

在此页面上:support.google.com/accounts/answer/185833请按照如何生成应用程序密码标题下的步骤进行操作。生成密码后,需要在配置中使用该密码。

On this page: support.google.com/accounts/answer/185833 follow the steps under the heading "How to generate an App password". After you generate it, you need to use that password in your configuration.

这篇关于带有smtp.gmail的Django电子邮件SMTPAuthenticationError 534需要特定于应用程序的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:20