【问题标题】:Django email with smtp.gmail SMTPAuthenticationError 534 Application-specific password required带有 smtp.gmail SMTPAuthenticationError 534 的 Django 电子邮件需要特定于应用程序的密码
【发布时间】:2015-04-09 21:47:12
【问题描述】:

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

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')

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

在我的 settings.py 中

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

我尝试在 django shell 中对此进行测试,但得到如上所示的错误:

>>> 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@email.com"]
>>> send_mail(sub,msg,from_user,to, fail_silently=False)

【问题讨论】:

    标签: python django email python-2.7


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的建议,但仍然无法正常工作 =/
    • 抱歉,我没有意识到您的帐户启用了 2 因素身份验证。您是否执行了 Google 支持页面上的所有步骤来生成应用程序密码,然后更新您的 EMAIL_HOST_PASSWORD 以使用该密码,而不是您的常规帐户密码?在此页面上:support.google.com/accounts/answer/185833 按照“如何生成应用程序密码”标题下的步骤操作。生成后,您需要在配置中使用该密码。
    • 效果不错!如果你更新你的答案,我会接受你的答案!
    【解决方案2】:

    好吧,您需要从您的 google 帐户生成密码(2 因素身份验证)。这是一次显示。 检查这个link 供指导。

    之后页面会提示输入密码并粘贴到你的settings.py中

    EMAIL_HOST_PASSWORD "your password goes here"
    

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2014-12-23
      • 2022-06-10
      • 2016-11-18
      • 1970-01-01
      • 2013-10-01
      • 2011-05-03
      • 2015-07-31
      相关资源
      最近更新 更多