1
votes

I am using the django auth views for password reset and setup the Email settings using smtp in settings.py. I am not sure why I am not receiving emails in my gmail. When I send it using the send_mail() function, I am getting emails fine. 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_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:

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. It shows me password_reset_done page but I do not receive any email in my gmail. Any help is greatly appreciated.

1

1 Answers

0
votes

in settings.py you are adding the django mail backend so you will receive the mail but in the server screen !! to receive the message in gmail you need to replace your settings with this settings

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

make sure to replace this settings and add your gmail and password

and you need to allow less secure apps in your gmail account from this link 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