Saturday, October 27, 2018

smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer

Django Python Error : SMTP Connection closed abruptly

If you are using Yandex smtp to send mails, here are the settings.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.com'
EMAIL_HOST_USER = 'username@domain.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587


Do not use port 465, try with port 587.

If still it does not work, you need to check the environment variables. Have you defined DEFAULT_FROM_EMAIL or HOST in OS environment files i.e. ~/.bashrc or /etc/environment
If they are there, it may be the issue, you need to comment them and loginto the new terminal as updated settings will be affected, now restart your web server (Python) and try again sending mails.

No comments:

Post a Comment