0
votes

I very new to django. I'm working in resetting password through email in django. I'm using all the 4 default class views. I can get upto PasswordResetDoneView where the page saying instructions have been sent to my mail. But I haven't received any mail.

Urls.py

from django.urls import path
from . import views
from django.contrib.auth.views import (
    LoginView,LogoutView,PasswordResetView,PasswordResetDoneView,PasswordResetConfirmView,PasswordResetCompleteView
    )

urlpatterns=[
    path('',views.home),
    path('login/',LoginView.as_view(template_name='accounts/login.html'),name='login page'),
    path('logout/',LogoutView.as_view(template_name='accounts/logout.html'),name='logout page'),
    path('register/',views.registration,name='register page'),
    path('profile/',views.profile,name='profile'),
    path('profile/edit_profile/',views.edit_profile,name='edit-profile'),
    path('profile/change-password/',views.change_password,name='edit-profile'),

    path('profile/reset-password/',PasswordResetView.as_view(),name='paassword_reset_view'),
    path('profile/reset-password/done/',PasswordResetDoneView.as_view(),name='password_reset_done'),
    path('profile/reset-password/confirm/<uidb64>/<token>/',PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
    path('profile/reset-password/complete/',PasswordResetCompleteView.as_view(),name='password_reset_complete'),
]

Also I have configured the settings.py file with the necessary configurations. I have also enabled the less secure option for the mail from which I'm sending the url. setting.py

EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
EMAIL_FILE_PATH = os.path.join(BASE_DIR, "sent_emails")
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'Password'

Also tried using send_mail separately in the shell. It returns 1.

Hoping for a solution

Thanks in advance

1

1 Answers

1
votes

Django will only send emails to active users who have a valid password. Write the following code in the shell to run a quick check for these two conditions:

from django.core.mail import send_mail
users = [(user.email, user.is_active, user.has_usable_password()) for user in get_user_model().objects.all()]
users

Second, you need to write a registered email in the password reset page. If you write an email that is not assigned to any of the users, the password reset email will NOT be sent (do not write your personal email in that field unless it is assigned to some user).

Finally, check the 'sent' folder of the sender's email to verify if the email was sent, and the spam folder of the receiver to verify if it was delivered.