25👍
To use port 465, you need to call smtplib.SMTP_SSL().
Currently, it calls smtplib.SMTP() ..
so,change your PORT from 465 into 587 it
if you want use PORT 465,
your EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_PORT=465
and you need to install django_smtp_ssl
otherwise you can keep,
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_PORT=465
3👍
For python3.0+
I found a workaround or maybe this is the solution , there is some issue in the django email package.
1)pip install sendgrid-django
2)Add these in the settings.py along with other email configurations
EMAIL_BACKEND = 'sgbackend.SendGridBackend'
SENDGRID_API_KEY = "YOUR SENDGRID API KEY"
EMAIL_PORT = 465
3)Code sample to send mail(yours maybe different):
from django.core.mail import EmailMessage
send_email = EmailMessage(
subject=subject,
body=body,
from_email=from_email,
to=to_email,
reply_to=reply_to,
headers=headers,
)
send_email.send(fail_silently=fail_silently)
You have to certainly make changes to the code as i was just showing a example.
For debugging purpose only-sendgrid mail send using telnet
- [Django]-Django form.as_p DateField not showing input type as date
- [Django]-Django runserver not serving static files in development
- [Django]-Using forloop.counter value as list index in a Django template
2👍
Please look into this Link: https://code.djangoproject.com/ticket/9575
and try sending via shell, it should work
- [Django]-Django: Is there a way to keep the dev server from restarting when a local .py file is changed and dynamically loaded?
- [Django]-STATIC_URL not working
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
2👍
I was developing and testing on localhost with the Gmail SMTP server and ran into this error. I figured out this was because I was using the EMAIL_PORT = 465
on a EMAIL_USE_TLS = True
configuration.
EMAIL_PORT = 465
is an SSL port configuration and is supposed to be used alongside the EMAIL_USE_SSL = True
configuration and not on a EMAIL_USE_TLS = True
configuration.
So anybody that will run into this issue in the future with same mistake as me should change that and everything should work fine. Below is what the full SMTP configuration looked like for me:
# Email server configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your_gmail_account@gmail.com'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxxxx'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
Also note that using TLS with EMAIL_PORT = 587
and EMAIL_USE_TLS = True
didn’t work for me on Gmail, so I had to switch to using SSL and it worked.
- [Django]-Django multiprocessing and database connections
- [Django]-Trying to trace a circular import error in Django
- [Django]-Django self-referential foreign key
- [Django]-Best practice for storing auth tokens in VueJS?
- [Django]-How to query Case-insensitive data in Django ORM?
- [Django]-Django REST Framework: Unique_together validation on Serializers
1👍
Like myself, if your deployed django app is on heroku and using https meaning you need port 465, you should not forget to add these same values below here to your heroku Config Vars
. It threw ‘connection unexpectedly closed’ error untill i had to add this.
# settings.py
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
# replace here with the long SendGrid API secret code
# xyxyxyxyzzzyz on heroku's Config Vars
EMAIL_PORT = 465
EMAIL_USE_SSL = True
Without that, debugging on localhost or development sever will work (with port 587 under http) but not at deployment under port 465 with https
- [Django]-Copy a database column into another in Django
- [Django]-What's the difference between authenticate and login?
- [Django]-Running a specific test case in Django when your app has a tests directory
1👍
I’m using AWS SES and was having the same problem.
Using port 587 worked for me. Settings were pretty much identical to @User0511
- [Django]-Django authentication – wrong redirect url to login page
- [Django]-ModuleNotFoundError: No module named 'grp' on windows
- [Django]-Default image for ImageField in Django's ORM
1👍
In my case the problem was that I used my api for EMAIL_HOST_PASSWORD.
Then I found my SMPT password by going to https://app.mailgun.com/app/sending/domains/
Clicked on my domain name
Then Selected on SMPT
- [Django]-Django form field required conditionally
- [Django]-Remove default apps from Django-admin
- [Django]-Django, name parameter in urlpatterns
0👍
Normally this is raised because wrong SENDGRID credentials
here you have to use
EMAIL_HOST_USER = ‘apikey’
- [Django]-Django: FloatField or DecimalField for Currency?
- [Django]-Running Django tests in PyCharm
- [Django]-Exclude a field from django rest framework serializer