Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: reset-password not sending email

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!

like image 646
user1670032 Avatar asked Dec 02 '13 10:12

user1670032


People also ask

How do I send an email using Django?

send_mail() In most cases, you can send email using django. core. mail. send_mail() .


2 Answers

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()]
like image 197
Paolo Melchiorre Avatar answered Oct 06 '22 15:10

Paolo Melchiorre


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

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

like image 33
eRIZ Avatar answered Oct 06 '22 15:10

eRIZ