I recently started to learn Django and I wrote a code to send an email in contact us page and it works fine in my localhost but when I uploaded it onto server it gave this error:
SMTPServerDisconnected at /contact
Connection unexpectedly closed
this is my settings.py code:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'app passwords'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
and this is my views.py
send_mail('title', 'message', userEmail, [settings.EMAIL_HOST_USER], fail_silently=False,)
I talked to the support group of my host server to check the ports but they said it was okay so I don’t know if I’m missing something or not.
New contributor
کوروش اردستانی is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.