0

I've used django's User model for authentication, now I added password reset for my project, User is not getting any email but in terminal I am getting this message, and I am doing all of these in my local computer

In my terminal

You're receiving this email because you requested a password reset for your user account at 127.0.0.1:8000.

Please go to the following page and choose a new password:

http://127.0.0.1:8000/accounts/reset/Mg/aisdmr-bd229ea69f64a159ed5c744816b02ca3/

Your username, in case you’ve forgotten: xxxxx

Thanks for using our site!

The 127.0.0.1:8000 team

In my urls.py

from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
    path('login/',
         auth_views.LoginView.as_view(template_name='accounts/login.html'),
         name='login'),
    path('logout/',
         auth_views.LogoutView.as_view(),
         name='logout'),
    path('signup/',
         views.SignUp.as_view(),
         name='signup'),
    path('user/<int:pk>/',
         views.UserList.as_view(template_name='accounts/about_user.html'),
         name='about_user'),
    path('reset_password/',auth_views.PasswordResetView.as_view(), name='reset_password'),
    path('reset_password_sent/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    path('reset_password_complete/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),

]

In settings.py

# SMTP configuration
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USER_TLS = True
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = 'password'

I've also enabled this in my EMAIL_HOST_USER enter image description here

pavan kumar
  • 125
  • 3
  • 10

1 Answers1

1

You have set in your settings EMAIL_BACKEND as:

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

Quoting Django's documentation on what this backend does:

Instead of sending out real emails the console backend just writes the emails that would be sent to the standard output.

Instead you want to use the SMTP backend:

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

Also you have a typo here EMAIL_USER_TLS = True it should be EMAIL_USE_TLS = True

Abdul Aziz Barkat
  • 19,475
  • 3
  • 20
  • 33
  • thanks @AbdulAzizBarkat, does this `EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'` also works in production server – pavan kumar Feb 28 '21 at 12:49
  • 1
    @pavankumar It would work but with a production server it would be better for you to use an email service. – Abdul Aziz Barkat Feb 28 '21 at 12:51
  • why not when it is free to use, is there any other issues with google – pavan kumar Feb 28 '21 at 12:54
  • 1
    @pavankumar There are many things to consider. 1) As a website mostly one wants to send and receive emails from multiple addresses (segregating emails according to concerned people, etc.). 2) With SMPT you end up using some common email address and now everyone ends up needing it's credentials, etc. 3) Also google limits the amount of emails you can send with SMTP. – Abdul Aziz Barkat Feb 28 '21 at 12:58