python - Django 通过 smtp.gmail.com 发送电子邮件时遇到问题

标签 python django smtp

我正在尝试配置 Django 的 send_email,以便我可以向用户发送密码重置电子邮件。到目前为止,我没有运气让它工作。我已经设置了一个基本的 Gmail 帐户(没有 Google App 等),在我的 Django settings.py 我有:

EMAIL_HOST      = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_HOST_USER = 'my_account@gmail.com'
EMAIL_PORT      = 587
MAIL_USE_TLS   = True

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL  = 'admin@my-site.com'

然后我尝试通过以下方式进行测试:

python manage.py shell
>>> from django.core.mail import send_mail
>>> send_mail('test', 'test', 'test@test.com', ['my-personal-email@gmail.com'])

然后我收到错误信息

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Program Files\Python27\lib\site-packages\django\core\mail\__init__.py
", line 62, in send_mail
    connection=connection).send()
  File "C:\Program Files\Python27\lib\site-packages\django\core\mail\message.py"
, line 255, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm
tp.py", line 88, in send_messages
    new_conn_created = self.open()
  File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm
tp.py", line 55, in open
    self.connection.login(self.username, self.password)
  File "C:\Program Files\Python27\lib\smtplib.py", line 577, in login
    raise SMTPException("SMTP AUTH extension not supported by server.")
SMTPException: SMTP AUTH extension not supported by server.

有没有人知道这是怎么回事!任何提示表示赞赏!

最佳答案

您在设置中输入错误。 TLS 应设置为 EMAIL_USE_TLS 而不是 MAIL_USE_TLS。连接到 587 时不使用 TLS 会生成此错误。

关于python - Django 通过 smtp.gmail.com 发送电子邮件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19746783/

相关文章:

django - 无法迁移,django.db.migrations.exceptions.MigrationSchemaMissing

python - 将 Django 对象输出到 XML-RPC 响应中

c# - 包含附件的 SmtpClient.Send 是否锁定附件?

Python 电子邮件,[Errno 10061] 无法建立连接,因为目标机器主动拒绝它

apache - 如何在测试开发服务器上使用 SMTP?

Azure 应用程序配置更改上的 Python 重新加载应用程序

python - 即使我发送 token ,django unittest : clien. 也会收到错误 401

python - 如何设置 celery 链中第一个任务的任务 ID?

python - Tf-Idf vectorizer 从行而不是单词分析向量

python - 为什么这个简单的条件表达式不起作用?