This is my settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com' # mail service smtp
EMAIL_HOST_USER = '[email protected]' # email id
EMAIL_HOST_PASSWORD = 'sdjlfkjdskjfdsjkjfkds' #password
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '[email protected]'
I am sending password reset email It works fine on localhost but on production server as sender I get webmaster@localhost
What do I do?
This is my urls.py
url(r'^password_reset/$', auth_views.PasswordResetView.as_view(
template_name='accounts/password_reset.html',
email_template_name = 'accounts/email/password_reset.html',
html_email_template_name = 'accounts/email/password_reset.html',
subject_template_name = 'accounts/email/password_reset_subject.html'),
First I want to explain why you get specifically webmaster@localhost email.
django.contrib.auth.forms.PasswordResetForm.save() function uses None as a from email address, webmaster@localhost is used by default, so you should just need to add DEFAULT_FROM_EMAIL property to your settings.py.
Connect to your production enviroment and run the django shell with python manage.py shell
.
Now run the following commands.
# Check your enviroment, should say something like production.
import os
os.environ.get('DJANGO_SETTINGS_MODULE')
# Check if the DEFAULT_FROM_EMAIL property is set.
from django.conf import settings
settings.DEFAULT_FROM_EMAIL
With os.environ.get('DJANGO_SETTINGS_MODULE')
you will get the settings file you are using for production, so if settings.DEFAULT_FROM_EMAIL
isn't set just edit that file and add it with your email.
Use another email backend (mandrill, sendgrid, etc...) to ensure that your mails will reach the inbox and not the spam folder.
For this you can use django-anymail package.
How to create a password reset view in Django - simpleisbetterthancomplex.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With