简体   繁体   中英

django2.1 send email fail:ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:833)

I want to send email to myself, so I tried it. I had set my email info in settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False 
EMAIL_USE_SSL = True   
EMAIL_HOST = 'smtp.163.com'  
EMAIL_PORT = 25     
EMAIL_HOST_USER = '*****@163.com'    
EMAIL_HOST_PASSWORD = '***'   

then I write down the example from django document

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    'from@example.com',
    ['to@example.com'],
    fail_silently=False,
)

then a exception happened

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:833)

How to fix it?

You should check that you are using the correct port number.

You probably need to change the port from 25 to 465 or 587 to use SMTP with SSL; port 25 is often used for non-encrypted email. Of course, it depends on your email provider, but it is kind of a standard followed by most providers.

For a little historical background on the port numbers, I found this (as one of many) article on the mailgun blog.

I encounter same error message while trying to send email via similar web framework (web2py) and a different email service provider (gmail).

Regardless of the different software components and different email servers, the solution are the same: double check the port of the email service you plan to use. For example, Gmail uses port 465 for SSL, but port 586 for TLS . After I get this right, the email can be sent as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM