0
votes

I try to reset password with gmail.com. I think I set everything correct, but it's still doesn't work and raise error like so: as you can see here

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_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')

I set my enviroment variables EMAIL_USER (login to my gmail account) and EMAIL_PASS (16-sign password provided by Google when you use 2-step authentication - Google App Password). I tried also use password to my gmail account but this also not work. Someone know what I do wrong ? Thanks for any help.

1
I don't use the django default for sending emails, I use smtplib to connect to he SMTP server and the email module for building the email. However my SMTP server port is 465 (for gmail) so try that?? If that doesn't work try just connecting to the SMTP server directly: Open python then import smtplib server = smtplib.SMTP_SSL('smtp.gmail.com', 465) account=os.environ.get('EMAIL_USER') password=os.environ.get('EMAIL_PASS') server.login(account,password) See if that connects okKJTHoward
Just a check: Does your gmail account have MFA enabled by any chance?dirkgroten
@dirkgroten Yes, MFA is enebled. I generated this 16-sign password and I try to log in using it. But as I see on my gmail account, it wasn't used yet, so something works wrong.Tomasz
Note that the password shown has dashes (-) to make it easily readable, but you must not put dashes in your code.dirkgroten
@dirkgroten Yes, I know that. I tried write it as one continuous expression as well as 4 sign parts divided by space but none of this works.Tomasz

1 Answers

0
votes

Change the EMAIL_PORT to be 465

EMAIL_PORT = 465

Using smtplib to connect directly to the gmail stmp server it fails with port 587 but works with 465:

server=smtplib.SMTP_SSL('smtp.gmail.com', 465)
account="MY ACCOUNT LOG IN"
password="MY APP PASSWORD"
server.login(account, password) 

returns:

(235, b'2.7.0 Accepted')

However

server=smtplib.SMTP_SSL('smtp.gmail.com', 587)
account="MY ACCOUNT LOG IN"
password="MY APP PASSWORD"
server.login(account, password)

Gives a time out error. And connecting without SSL isn't supported for gmail:

server=smtplib.SMTP('smtp.gmail.com', 587)
account="MY ACCOUNT LOG IN"
password="MY APP PASSWORD"
server.login(account, password)

Returns

smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.