Django 3 - password reset - not generating email - python

I've followed multiple sources on how to set this up. Now everything seems working (no error) but I just don't see the email.
gmail - Allow less secure apps: ON
url.py
path('pw_reset/', auth_views.PasswordResetView.as_view(template_name="authacc/pw_reset.html"), name="reset_password"),
path('pw_done/', auth_views.PasswordResetDoneView.as_view(template_name="authacc/pw_done.html"), name="password_reset_done"),
path('pw_confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name="authacc/pw_confirm.html"), name="password_reset_confirm"),
path('pw_complete/', auth_views.PasswordResetCompleteView.as_view(template_name="authacc/pw_complete.html"), name="password_reset_complete"),
settings.py
#SMTP Configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
What I've tried...
use debuggingserver to check the email locally.
settings.py
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
cmd
python -m smtpd -n -c DebuggingServer localhost:1025
I can see the "Password reset sent" page, but no email is generated. So I suspect there's something wrong with the default PasswordResetView?
Probably similar problem, but unresolved:
Reset password emails in Django

The code was fine. Something was off with the email formatting. I didn't experiment enough, but ".com" ending seems fine, ".me" isn't.

Related

Django isn't able to send emails but can login into my gmail acc

My Django app is able to log in into my Gmail account, but it is not sending emails.
I know it logged in because I tried sending an email to a non-existing email-address and Gmail gave me this error.
Even looked in my spam folders but nothing :(
However, when I manually send an email, it works properly.
This is my SMTP configuration in settings.py
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
I even tried hard-coding and changing the sender's email, but still no result.
I wasn't getting this error a few days before, but for some reason it does seem to be working now.
By the way, I'm using this for password reset functionality.

Error in sending email using gmail smtp in Django app

I set up everything as the Django documentation but when I test sending an email.It works but When I check my inbox I find out that I sent and revived from to the same email address.
Here is the settings.py
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "myemail#gmail.com"
EMAIL_HOST_PASSWORD = "mypassword"
And the views.py
...
send_mail( 'subject', 'message', 'user#gmail.com', ['myemail#gmail.com',], fail_silently=False, )
...
But I received an email from myemail#gmail.com to me(myemail#gmail.com).
Im not sure if you did this already but if youre using gmail then you will need to do the following.
Sign in to your Google Admin console (Sign in using an administrator account)
Click Security > Less secure apps.
Select Allow users to manage their access to less secure apps.
Click Save.25
Also you should use environment variables for the email address if you are live already eg:
EMAIL_HOST_USER = os.environ.get('MY_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('MY_EMAIL_PASS')
If its all working and you are just getting the mail to the wrong address can you send on the document you followed?
In terms of you settings.py that looks fine to me.

python django email set correct sender gunicorn

This is my settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com' # mail service smtp
EMAIL_HOST_USER = 'xx#xx.com' # email id
EMAIL_HOST_PASSWORD = 'sdjlfkjdskjfdsjkjfkds' #password
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'xx#xx.com'
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.
Explanation
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.
Solution
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.
Recomendations
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.
References
How to create a password reset view in Django - simpleisbetterthancomplex.com

Sending Email with Django

I'm trying to send email with django. Here's my settings.py file.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'mymail#gmail.com'
EMAIL_HOST_PASSWORD = 'mailpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'mymail#gmail.com'
I've also enabled access to less secure apps in the gmail settings.
On the production server whenever I try to send an email, it's raising an error in the command line upstream prematurely closed connection while reading response header from upstream.
On webpage it's showing 502 Bad Gateway error.
How can we solve this issue? Thank You . . .

Setting up Email Backends with Django 1.6

I currently am using django-password-reset to assist users when they forget a password. Everything worked just fine while in development but now I am having issues setting up the email backend on my production server.
When a user enters their username or email into the password reset form and push the 'Recover Password' button that would normally trigger the password-reset email, the page starts to load infinitely. I am attempting to use a gmail account as my smtp server. I am assuming that there is some sort of issue with my settings.py file.
settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'example#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example#gmail.com'
If you have any idea what is wrong with my configuration or any other ways to set up my email backend advice would be greatly appreciated! Thanks
This works locally at least.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'something#gmail.com'
EMAIL_HOST_PASSWORD = 'something'
EMAIL_USE_TLS = True

Categories