Django: reset-password not sending email
Asked Answered
P

9

14

I am using the Django password reset.

I have this code in my settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SERVER_EMAIL = '[email protected]'

It redirects me to the right page, but it doesn't send the email. I have checked the Spam folder and such, but still nothing :(

Any ideas are much appreciated!

Edit

I have tried to test it using the console but I get the following error:

>>> email = EmailMessage('Mail test', 'this is a test', to=['[email protected]'])
>>> email.send()

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 88, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 55, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python2.7/smtplib.py", line 576, in login
raise SMTPException("SMTP AUTH extension not supported by server.")

SMTPException: SMTP AUTH extension not supported by server.

Edit

I have the settings.py configured as above. For some reason it wasn't working before, but now it seems to be. When I run

python manage.py shell

and test it using the EmailMessage and send() function, I get a status code of 1, and I receive the email. However, I am still not getting the email from the password_reset. Any ideas? Thanks everyone for your input!

Pembrook answered 2/12, 2013 at 10:14 Comment(2)
Do you have two factor authentication enabled on your account?Agitato
I have never touched that before. When I go to check it out, it says I have to set it up. Is it set up by default?Pembrook
P
21

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()]
Panettone answered 18/12, 2018 at 9:42 Comment(2)
In addition (perhaps too obvious)...: Make sure the value of u.email is actually a valid email address.Utopian
Thank you. The superadmin user used to test the feature didn't have an email address.Sprung
A
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

Aplenty answered 2/12, 2013 at 10:19 Comment(2)
It can use both, in fact its right there in the link you posted.Agitato
"but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL)" - I had no problems using 465+SSL.Aplenty
D
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.', '[email protected]',
['[email protected]'], 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

Dorm answered 2/12, 2013 at 10:23 Comment(2)
I have actually tried something similar to this, and I get the error above. I have edited my original post.Pembrook
Did you use the builtin views? Can you post your password_reset function?Dorm
A
2

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

Awake answered 2/12, 2013 at 12:12 Comment(1)
It seems to be working with port 587. However, the actual password reset view seems to not be sending the e-mail.Pembrook
T
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.

Torquemada answered 13/12, 2018 at 5:21 Comment(0)
C
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

Caterinacatering answered 14/12, 2018 at 15:38 Comment(0)
L
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>'])
Luanneluanni answered 17/12, 2018 at 14:18 Comment(0)
S
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)
Spotty answered 30/5, 2021 at 14:11 Comment(0)
P
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.

Pulcheria answered 7/12, 2021 at 10:54 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Willed

© 2022 - 2024 — McMap. All rights reserved.