简体   繁体   English

重置 Django 中的密码电子邮件

[英]Reset password emails in Django

I am using the django auth views for password reset and setup the Email settings using smtp in settings.py.我正在使用 django 身份验证视图进行密码重置,并使用 settings.py 中的 smtp 设置 Email 设置。 I am not sure why I am not receiving emails in my gmail.我不确定为什么在我的 gmail 中没有收到电子邮件。 When I send it using the send_mail() function, I am getting emails fine.当我使用 send_mail() function 发送它时,我收到的电子邮件很好。 Does anybody has any idea?有人知道吗?

I have configured EMAIL settings in settings.py and added URLs in url.py and made my own template files.我在 settings.py 中配置了 EMAIL 设置,并在 url.py 中添加了 URL,并制作了我自己的模板文件。

Settings.py:设置.py:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PWD')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

urls.py:网址.py:

from django.contrib.auth import views as auth_views

 path('password-reset/',
         auth_views.PasswordResetView.as_view(
             template_name='users/password_reset.html'
         ),
         name='password_reset'),
    path('password-reset/done/',
         auth_views.PasswordResetDoneView.as_view(
             template_name='users/password_reset_done.html'
         ),
         name='password_reset_done'),
    path('password-reset-confirm/<uidb64>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(
             template_name='users/password_reset_confirm.html'
         ),
         name='password_reset_confirm'),
    path('password-reset-complete/',
         auth_views.PasswordResetCompleteView.as_view(
             template_name='users/password_reset_complete.html'
         ),
         name='password_reset_complete'),
    path('admin/', admin.site.urls),

I go to the password_reset and enter my email and click Submit.我将 go 设置为密码重置并输入我的 email 并单击提交。 It shows me password_reset_done page but I do not receive any email in my gmail.它显示了 password_reset_done 页面,但我在 gmail 中没有收到任何 email。 Any help is greatly appreciated.任何帮助是极大的赞赏。

in settings.py you are adding the django mail backend so you will receive the mail but in the server screen !!在 settings.py 中,您正在添加 django 邮件后端,因此您将在服务器屏幕中收到邮件! to receive the message in gmail you need to replace your settings with this settings要接收 gmail 中的消息,您需要使用此设置替换您的设置

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

make sure to replace this settings and add your gmail and password确保替换此设置并添加您的 gmail 和密码

and you need to allow less secure apps in your gmail account from this link https://myaccount.google.com/lesssecureapps?pli=1并且您需要通过此链接在您的 gmail 帐户中允许安全性较低的应用程序https://myaccount.google.com/lesssecureapps?pli=1

if it still not working disable the captcha from here https://accounts.google.com/displayunlockcaptcha hope this helps如果它仍然不起作用,请从此处禁用验证码https://accounts.google.com/displayunlockcaptcha希望这会有所帮助

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

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