[Fixed]-Django: reset-password not sending email

19👍

As your sending test in Django shell works it means that your email settings are well configured.

If you still not getting the email from the password_reset you have to search your problem in this field.

You have to know that the password reset email is sent only to active users (is_active), and only if they have an usable password (has_usable_password).

If an user has an invalid password, Django will just silently not send the reset email.

Use the following code in the Django shell to test all your users:

from django.contrib.auth import get_user_model

[(u.email, u.is_active, u.has_usable_password()) for u in get_user_model().objects.all()]

2👍

GMail uses SSL, not a TLS. Is that why your app cannot contact their servers.

https://support.google.com/mail/answer/78775?hl=en

👤eRIZ

2👍

Try if the mail is sent or not:
./manage.py shell

from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)

if the return is 0, then you have to reconfigure your email settings. Make sure you input the right credential. Check the documentation https://docs.djangoproject.com/en/dev/topics/email/#send-mail

2👍

Set EMAIL_PORT = 25. Gmail uses SSL connection, you need to set EMAIL_PORT = 25

👤Nilesh

2👍

This is a long shot, but weirdly enough I don’t have EMAIL_BACKEND set in my settings file. I thought I did, but as I just looked through it I could not find it. I don’t use Gmail, but my email sending works fine, including password reset. Also, looking at your error log in the console, it seems to be related to ‘backend’. So my answer is: try removing the EMAIL_BACKEND setting.

2👍

In gmail create a separate password for mail sending (as app) located in advanced settings
It should be around 12-16 characters in length

Then give it a try

2👍

Add below settings

# ....
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '<your gmail>'
EMAIL_HOST_PASSWORD = '<your password>'
EMAIL_USE_TLS = True
# ....

Now, try to send an email from django shell

from django.core.mail import send_mail
send_mail('Subject', 'Body infromation', '<your from email>', ['<your to email>'])

1👍

Your settings appear to be correct

You must first see if you are logged in

also you can use this in your main url

from django.contrib.auth import views as auth_views

path('reset_password/',auth_views.PasswordResetView.as_view(),name='password_reset)

0👍

That’s how I fixed this issue:

I was also facing this issue. But when I checked my database, my database was empty. There was not a single user in my database. So, make sure you have a user in your database with this email.

Leave a comment