django – ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)

huangapple go评论52阅读模式
英文:

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

这是导致错误的配置问题:

  1. 您的 EMAIL_BACKEND 未正确指定。
  2. 您正确使用端口 587 用于 EMAIL_PORT,但 EMAIL_USE_TLSFalse
  3. 不能同时将 EMAIL_USE_TLSEMAIL_USE_SSL 都设置为 False

更正:

  1. EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

  2. 如果将 EMAIL_USE_SSL 设置为 False

    EMAIL_USE_SSL = False
    EMAIL_USE_TLS = True
    EMAIL_PORT = 587
    
  3. 如果将 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:

  1. Your EMAIL_BACKEND is not correctly specified.
  2. You are correctly using port 587 for the EMAIL_PORT but EMAIL_USE_TLS is False.
  3. You can't set both EMAIL_USE_TLS and EMAIL_USE_SSL to False.

Corrections:

  1. EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

  2. If you are setting EMAIL_USE_SSL to False:

    EMAIL_USE_SSL = False
    EMAIL_USE_TLS = True
    EMAIL_PORT = 587
    
  3. If you are setting EMAIL_USE_TLS to False:

    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.

huangapple
  • 本文由 发表于 2023年2月24日 16:22:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554137.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定