K
K
Kwad2020-05-28 13:28:43
Django
Kwad, 2020-05-28 13:28:43

Why doesn't Django + Google SMTP send emails?

I decided to do a password recovery, it didn’t work through postfix, I decided to do it through Google mail,
Here are the settings.py:

spoiler
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

Throws an error when submitting:
browser error
TimeoutError at /accounts/password/reset/

[Errno 110] Connection timed out

Console:
spoiler
5ecf918990bb4272139455.png

How to fix and where is the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Eremin, 2020-05-30
@Sergei_Erjemin

Googling what's missing:

EMAIL_USE_SSL = False
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

or even:
EMAIL_USE_SSL = False
SERVER_EMAIL = DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

And yet, maybe you have two-factor authentication, and then your application is not authorized ... read here: https://support.google.com/accounts/answer/6010255 ... then you need to either disable two-factor authentication, or the application should be signed and specify the keys EMAIL_SSL_CERTFILEand in the networking EMAIL_SSL_KEYFILE... or use not gmail, but something else ...
In addition, in order not to fall on the timeout - put an exception on this event, and / or use EMAIL_TIMEOUT
PS in the networking Sending mail from the application - - slow stuff. Even if nothing falls, the user notices a slowdown (2-3 seconds or more). So it is better to send mail asynchronously or in a parallel stream. For example, using the django_background_tasks module...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question