Sahil Tariq
Sahil Tariq

Reputation: 138

SMTPSenderRefused at /password-reset/ - Django

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('USER_EMAIL')
EMAIL_HOST_PASSWORD = os.environ.get('USER_PASS')

Error:

SMTPSenderRefused at /password-reset/
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError h10-20020a170902680a00b0015e8d4eb1d5sm14008586plk.31 - gsmtp', 'webmaster@localhost')
Request Method: POST
Request URL:    http://localhost:8000/password-reset/
Django Version: 4.1.1
Exception Type: SMTPSenderRefused
Exception Value:    
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError h10-20020a170902680a00b0015e8d4eb1d5sm14008586plk.31 - gsmtp', 'webmaster@localhost')
Exception Location: C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\smtplib.py, line 887, in sendmail
Raised during:  django.contrib.auth.views.PasswordResetView
Python Executable:  D:\Django\Tutorial\env\Scripts\python.exe
Python Version: 3.10.2
Python Path:    
['D:\\Django\\Tutorial\\django_project',
 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\lib',
 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310',
 'D:\\Django\\Tutorial\\env',
 'D:\\Django\\Tutorial\\env\\lib\\site-packages']
Server time:    Fri, 16 Sep 2022 06:10:41 +0000

urls.py:

    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("", include('blog.urls')),

I am trying to set an email password reset in my Django app but get this unexpected error. What I am trying to do here is I am using Django inbuild views PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView to reset my registered account's password through email.

Can you help me with this or provide me with some links so I can reach the core of this error?

Upvotes: 4

Views: 602

Answers (2)

Kariuki John
Kariuki John

Reputation: 11

Here is detailed link to solve that problem, pay attention to system variables set to be similar to those set on settings.py here

Upvotes: 0

Sahil Tariq
Sahil Tariq

Reputation: 138

I have solved the issue the issue was with my Gmail account you need to go to the settings > security then create a new app password and then replace the Gmail password in settings.py with your newly created app password.

I think your Gmail should also have 2-factor authentication, mine was already on but if you try this I think you should first try to turn on the 2-factor authentication and then try all these steps.

Upvotes: 3

Related Questions