[英]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 我已经在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 然后我从Django文档中写下示例
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; 您可能需要将端口从25更改为465或587,以将SMTP与SSL配合使用; port 25 is often used for non-encrypted email. 端口25通常用于非加密电子邮件。 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. 对于端口号的一些历史背景,我在mailgun
博客上找到了这篇文章 (作为众多文章之一)。
I encounter same error message while trying to send email via similar web framework (web2py) and a different email service provider (gmail). 尝试通过类似的Web框架(web2py)和其他电子邮件服务提供商(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 . 例如, 对于SSL , Gmail使用端口465,对于TLS使用端口586 。 After I get this right, the email can be sent as expected. 正确后,即可按预期发送电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.