我正在使用内置的 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/