Reputation: 1153
I'm trying to implement django's built-in forgot password, but I never receive the email. I've checked my spam folder and still nothing. It shows me the password reset sucessful page after typing in the email but I never get the email.
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'something'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
urls.py
url(r'^forgot-password/$', views.forgot_password, name="forgot-password"),
views.py
def forgot_password(request):
if request.method == 'POST':
return password_reset(request,
from_email=request.POST.get('email'))
else:
return render(request, 'meddy1/forgot_password.html')
I've tried testing it in the python manage.py shell by doing the following
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Message', to=['[email protected]'])
email.send()
It gives me the output of 1 but i still don't get any email!!
I then tried this python manage.py shell by doing the following
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', '[email protected]',
['[email protected]'], fail_silently=False)
It gives me the output of 1 and I successfully receive the email in my inbox.
I have no idea why it's not sending the email through the form.
Upvotes: 2
Views: 501
Reputation: 1153
The reason why I was not getting the email was because I was storing the user's email address as the username on signup. Because I wanted to authenticate using email address instead of username. So whenever I entered the email address in the forgot password page it would redirect me to the page saying the email has been sent. But I'd never get any email because it never found the email in the database. Ideally, It should actually raise an error saying email address not found. But it doesn't!!!
I need to find a way to do that.
So currently I'm saving the user's email address as username and email address. I know it's not a good idea to do that because of data redundancy. But it works!
Upvotes: 1