gmail和Django注册未发送重置密码电子邮件

gmail和Django注册未发送重置密码电子邮件,django,email,passwords,gmail,Django,Email,Passwords,Gmail,我正试图用gmail发送一封重置密码的电子邮件。在填写有效的电子邮件地址并提交发送后,下面的重置功能将工作并重定向到“成功”页面,但没有发送邮件。所有注册模板都存储在同一目录中;myapp/注册 在场景中 import smtplib EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 #465 EMAIL_HOST_PASSWORD = 'yourpassword' EMAIL_HOST_USER = 'youremail@gmail.com' #EM

我正试图用gmail发送一封重置密码的电子邮件。在填写有效的电子邮件地址并提交发送后,下面的重置功能将工作并重定向到“成功”页面,但没有发送邮件。所有注册模板都存储在同一目录中;myapp/注册

在场景中

import smtplib
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587 #465
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_HOST_USER = 'youremail@gmail.com'
#EMAIL_SUBJECT_PREFIX = 'something'
EMAIL_USE_TLS = True
在URL中

   url(r'^password/change/$',
                    auth_views.password_change,
                    {'post_change_redirect': reverse_lazy('auth_password_change_done')},
                    name='password_change'),
   url(r'^password/change/done/$',
                    auth_views.password_change_done,
                    name='password_change_done'),
   url(r'^password/reset/$',
                    auth_views.password_reset,
                    {'post_reset_redirect': reverse_lazy('auth_password_reset_done')},
                    name='password_reset'),
   url(r'^password/reset/done/$',
                    auth_views.password_reset_done,
                    name='password_reset_done'),
   url(r'^password/reset/complete/$',
                    auth_views.password_reset_complete,
                    name='password_reset_complete'),
   url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
                    auth_views.password_reset_confirm,
                    {'post_reset_redirect': reverse_lazy('auth_password_reset_complete')},
                    name='password_reset_confirm'),

      #and now add the registration urls
   url(r'', include('registration.backends.default.urls')),
更新

我的电子邮件现在被发送到gmail,但gmail提供了以下错误信息

Delivery to the following recipient failed permanently:

     to_email_address@gmail.com

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain gmail.com by gmail-smtp-in.l.google.com. [2a00:1450:4010:c04::1b].

The error that the other server returned was:
550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 http://support.google.com/mail/bin/answer.py?answer=6596 ok4si3174885lbb.110 - gsmtp


----- Original message -----

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=from:content-type:mime-version:content-transfer-encoding:subject:to
         :date:message-id;
        bh=XIT/LAmN67IRi9HrLcISdd0LCPh/Bo8BtcnOZ3a1r2M=;
        b=jIlBIOhiXVxumR9TmTigQTJL23bh5NiaGHVZr7zOdIbVaQ/o3Ud3F7S7xlYdgrdF7X
         f8kZwMY59Q405rfxv5dmkDm5cAu7XTHJANpbhdMgk0zDySh9ohxJSPDNZ53fMDMubPZN
         Y2HAYFGrB51nyld/wSfBJ/tOgxZ25kA//g/1wLhfCZOiU5zOVlMhl/T38W7bIRXpgSuy
         MwPWeUWJ7HfLOaCbuXNcizVvUxzieq5aKrIw5I16TmNfkp40oCR3oBnBR1hx8gvPim4x
         6IR+GhAwo5Zj9XNmFhnIp/EjxU4DV9OsgUelAqfyPRQ80M4RWE/qaWXqxJs2HGJ6+2gI
         bc/w==
X-Received: by 10.112.61.136 with SMTP id p8mr23610717lbr.107.1429696044965;
        Wed, 22 Apr 2015 02:47:24 -0700 (PDT
)

我认为这可能与重置视图绑定到Django admin视图有关,因此我尝试通过使用我自己的base.html扩展注册模板来更改注册模板,正如在本博客中所做的那样,但它不适用于。我还在视图中添加了以下更改密码功能

在URL.py中

   url(r'^password/change/$',
                     auth_views.password_change,
                     {'post_change_redirect': reverse_lazy('auth_password_change_done')},
                     name='my_password_change'),
    url(r'^password/change/done/$',
                     auth_views.password_change_done,
                     name='password_change_done'),
    url(r'^password/reset/$',
                     auth_views.password_reset,
                     {'post_reset_redirect': reverse_lazy('auth_password_reset_done')},
                     name='password_reset'),
    url(r'^password/reset/done/$',
                     auth_views.password_reset_done,
                     name='password_reset_done'),
    url(r'^password/reset/complete/$',
                     auth_views.password_reset_complete,
                     name='password_reset_complete'),
    url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
                     auth_views.password_reset_confirm,
                     {'post_reset_redirect': reverse_lazy('auth_password_reset_complete')},
                     name='password_reset_confirm'),

      #and now add the registration urls
   url(r'', include('registration.backends.default.urls')),

在运行代码后,您是否尝试登录到Gmail帐户

你可能必须允许你的应用程序使用你的Gmail发送电子邮件


不幸的是,在您编写的查看函数中,我没有看到任何邮件发送代码(即,
发送邮件(…)
),它可能位于
密码重置
密码重置
表单中。您需要添加该选项以发送电子邮件(例如),如下所示:

from django.core.mail import send_mail

send_mail('subject', 'email_body', 'from_email_address@gmail.com' , ['to_email_address@gmail.com'], fail_silently=False)

这是我通过gmail smtp在django中发送邮件的工作配置:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youruser@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

你能发其他电子邮件吗?你能把代码简化到最简单的部分吗?更容易排除故障。测试时,它在终端中工作。代码来自Django的docsI,我现在尝试通过链接将gmail设置更改为允许不太安全的应用程序,并收到了一封来自谷歌的确认电子邮件,但我仍然没有收到应用程序发送的重置电子邮件。它可以发送邮件,gmail接收邮件,但不会接受,我已经用收到的错误消息更新了信息。这可能与仍在使用的Django admin重置视图有关吗?我已尝试覆盖Django admin reset视图,但它不会更改为我的基本视图。HTMLY您需要添加一个有效的邮件地址来接收电子邮件,这就是您收到该错误的原因。对于实现,django admin reset视图的使用方式如下:,覆盖很容易。以下是我如何实现的,来源:@user1749431
from django.core.mail import send_mail

send_mail('subject', 'email_body', 'from_email_address@gmail.com' , ['to_email_address@gmail.com'], fail_silently=False)
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youruser@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True