6

我想使用 Outlook 的 SMTP 服务器在 Django 应用程序中发送电子邮件。问题是,每次我尝试发送消息时都会收到SSL 错误版本号错误。

错误回溯:

Traceback (most recent call last):
File "F:\Development\Python\lib\smtplib.py", line 366, in getreply
    line = self.file.readline()
File "F:\Development\Python\lib\socket.py", line 297, in readinto
    return self._sock.recv_into(b)
File "F:\Development\Python\lib\ssl.py", line 453, in recv_into
    return self.read(nbytes, buffer)
File "F:\Development\Python\lib\ssl.py", line 327, in read
    v = self._sslobj.read(len, buffer)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1450)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "F:\Development\Python\lib\site-packages\django\core\handlers\base.py", line 115,   in get_response
    response = callback(request, *callback_args, **callback_kwargs)
File "E:\SkyDrive\Repositories\web\skyproject\views.py", line 13, in index
    email.send()
File "F:\Development\Python\lib\site-packages\django\core\mail\message.py", line 255, in send
    return self.get_connection(fail_silently).send_messages([self])
File "F:\Development\Python\lib\site-packages\django\core\mail\backends\smtp.py", line 88, in send_messages
    new_conn_created = self.open()
File "F:\Development\Python\lib\site-packages\django\core\mail\backends\smtp.py", line 55, in open
    self.connection.login(self.username, self.password)
File "F:\Development\Python\lib\smtplib.py", line 621, in login
    AUTH_PLAIN + " " + encode_plain(user, password))
File "F:\Development\Python\lib\smtplib.py", line 398, in docmd
    return self.getreply()
File "F:\Development\Python\lib\smtplib.py", line 370, in getreply
+ str(e))

smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1450)

这是我在“settings.py”中的 SMTP 配置:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.live.com'
EMAIL_HOST_USER = 'my_email@outlook.com'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_PORT = 587

这就是发送消息的方式:

from django.core.mail import EmailMessage
email = EmailMessage('Test', 'Test', to=['email_address@example.com'])
email.send()

我不知道为什么会收到此错误。据我所知,Django 设置中没有 SSL_VERSION 参数。

如果重要的话,我的解释器的版本是3.3.2,而 Django 的版本是1.5.2

4

3 回答 3

1

我有一个非常相似的问题。我收到以下错误消息:

SMTPServerDisconnected: Connection unexpectedly closed

解决方案是:

  1. 通过 www.outlook.com 上提供的 Web 界面登录到电子邮件地址
  2. 通过向 MS 提供我的电话号码并输入收到的 SMS 来验证我的帐户。

在此之后,我可以很好地从 Django 发送电子邮件。

于 2014-02-24T20:40:23.513 回答
1

我让它使用以下设置:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'myemail@outlook.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25
于 2013-10-11T21:39:05.513 回答
0

为 OutLook 尝试以下设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = "youremail@outlook.com"
EMAIL_HOST_PASSWORD = "yourpassword"
于 2021-03-17T11:46:46.720 回答