django send_email() 显示成功但未收到电子邮件

django send_email() shows success but no email received

我正在学习如何在 Djgnao 中发送电子邮件。我已配置

# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<my username>@gmail.com'
EMAIL_HOST_PASSWORD = '<my password>'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

django shell 中,我尝试向自己(以及我的朋友)发送电子邮件

>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.', "<my username>@gmail.com", ["<my username>@gmail.com"])

它 returns 结果看起来很成功

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Subject here
From: <my username>@gmail.com
To: <my username>@gmail.com
Date: Wed, 21 Jan 2015 17:55:20 -0000
Message-ID: <20150121175520.31612.19817@<my username>>

Here is the message.
---------------------------------------------------------------------
1

但是查看我的邮箱和朋友的邮箱,没有收到这样的邮件。

我是不是误会了什么?或者我需要对我的 Gmail 帐户做些什么吗?


实际上,我在 https://support.google.com/a/answer/182076?hl=en 中尝试了 [登录管理控制台],但我在 "re-enter your password" 页面和 "choose an account or add a new account" 页面之间被重定向。我正在试用我的免费普通个人 Google 帐户,这是问题所在吗?

问题是,您的设置是

EMAIL_BACKEND = django.core.mail.backends.console.EmailBackend

这意味着email message prints to console

Instead of sending out real emails the console backend just writes the emails that would be sent to the standard output. By default, the console backend writes to stdout. You can use a different stream-like object by providing the stream keyword argument when constructing the connection.

将其更改为

EMAIL_BACKEND = django.core.mail.backends.smtp.EmailBackend

让 SMTP 正常工作。这是 relevant documentation