繁体   English   中英

无法使用Django和Python发送电子邮件

[英]Email could not sent using Django and Python

我已经使用Django实现了重置密码功能。 在这里,我将重设密码链接发送到已注册的电子邮件,并且收件箱中没有邮件。 我的代码如下。

settings.py:

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

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user474@gmail.com'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'user474@gmail.com'

registration / password_reset_form.html:

{% extends 'base.html' %}

{% block content %}
  <h3>Forgot password</h3>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Submit</button>
  </form>
{% endblock %}

registration / password_reset_email.html:

    {% autoescape off %}
    To initiate the password reset process for your {{ user.get_username }} TestSite Account,
    click the link below:

    {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

If clicking the link above doesn't work, please copy and paste the URL in a new browser
window instead.

Sincerely,
The Nuclear Team
{% endautoescape %}

我的密码重置表格如下所示。

在此处输入图片说明

在这里,我无法将邮件发送到给定的电子邮件ID。

姚需要更换:

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

BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
#                                   ^^^^^^

此处有更多信息: 电子邮件后端

您应该对自己的观点有如下看法:

from django.core.mail import EmailMessage

email = EmailMessage('title', 'body', to=[email])
email.send()

另外,您还需要解锁Gmail帐户上的验证码: https : //accounts.google.com/DisplayUnlockCaptcha

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM