python - Django 密码重置电子邮件从不发送

标签 python django email smtp

我正在使用内置的 Django 密码重置,出现“已发送密码重置”页面,但电子邮件从未发送。我的电子邮件设置设置如下:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'my_email'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = 'my_password'

我在开发中包含了以下内容,但不确定是否有必要:

ALLOWED_HOSTS = ['localhost']

控制台显示:

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Password reset on localhost:8000
From: myemail@gmail.com
To: anotheremail@hotmail.com
Date: Wed, 17 Feb 2016 04:53:17 -0000
Message-ID: <some_id@toms-macbook-air.local>

看起来一切都在发生,但电子邮件从未发送。我在这里做错了什么吗?

最佳答案

您正在使用仅用于测试的虚拟电子邮件后端。换行

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

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

来自docs :

Console backend

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.

关于python - Django 密码重置电子邮件从不发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35448299/

相关文章:

html - 包含将在 Gmail/邮箱应用程序中打开的带有主题和正文的 mailto 网址

python - 创建 exe 时如何在 PyInstaller 中提供图标的相对路径

python - 我可以过滤用户以要求在给定范围内的每个日期都匹配条目吗?

php - 空白多部分电子邮件

python - 具有系统时区设置的 Django 与用户的个人时区

python - Django 时区 : How to compare time difference in days between 2 days across DST

java - Google App Engine Java 从备用电子邮件地址发送邮件

python - 多处理和垃圾收集

python - 动态选择函数

python:以通用方式获取嵌套字典的值