英文:
django - ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)
问题
我正在尝试在Django中发送电子邮件,但无法成功。我一直在收到一个SSLError(使用下面的代码)或者在使用端口465时超时。
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = config['EMAIL']
EMAIL_HOST_PASSWORD = config['PASSWORD']
DEFAULT_FROM_EMAIL = config['EMAIL']
EMAIL_USE_SSL = False
EMAIL_USE_TLS = False
EMAIL_USE_STARTTLS = True
我该如何解决这个问题?
英文:
I'm trying to send an email in django, but I can't. I keep getting an SSLError (With the code below) or I get timed out (When I use port 465)
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = config['EMAIL']
EMAIL_HOST_PASSWORD = config['PASSWORD']
DEFAULT_FROM_EMAIL = config['EMAIL']
EMAIL_USE_SSL = False
EMAIL_USE_TLS = False
EMAIL_USE_STARTTLS = True
How do I fix this?
答案1
得分: 0
这是导致错误的配置问题:
- 您的
EMAIL_BACKEND
未正确指定。 - 您正确使用端口
587
用于EMAIL_PORT
,但EMAIL_USE_TLS
为False
。 - 不能同时将
EMAIL_USE_TLS
和EMAIL_USE_SSL
都设置为False
。
更正:
-
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
-
如果将
EMAIL_USE_SSL
设置为False
:EMAIL_USE_SSL = False EMAIL_USE_TLS = True EMAIL_PORT = 587
-
如果将
EMAIL_USE_TLS
设置为False
:EMAIL_USE_SSL = True EMAIL_USE_TLS = False EMAIL_PORT = 465
有关更多信息,请参阅 Django 的电子邮件发送文档此处。
英文:
Here are the configuration issues that are causing this error:
- Your
EMAIL_BACKEND
is not correctly specified. - You are correctly using port
587
for theEMAIL_PORT
butEMAIL_USE_TLS
isFalse
. - You can't set both
EMAIL_USE_TLS
andEMAIL_USE_SSL
toFalse
.
Corrections:
-
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
-
If you are setting
EMAIL_USE_SSL
toFalse
:EMAIL_USE_SSL = False EMAIL_USE_TLS = True EMAIL_PORT = 587
-
If you are setting
EMAIL_USE_TLS
toFalse
:EMAIL_USE_SSL = True EMAIL_USE_TLS = False EMAIL_PORT = 465
For further information, you can refer to Django's documentation on email sending here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论