Python Smtp SSL wrong version on linux

时光毁灭记忆、已成空白 提交于 2019-12-08 01:49:05

问题


My code to send emails via msft outlook.com works on windows but not on my linux box. Any idea how to fix this?

import smtplib
smtp = smtplib.SMTP('smtp.live.com', port=587)
smtp.starttls()
smtp.login(username, password)

SMTPServerDisconnected: Connection unexpectedly closed: 
[Errno 1] _ssl.c:1359: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

EDIT: more details: gentoo linux with python 2.7.3, openssl 0.9.8x and 1.0.1c


回答1:


I bet the problem is on the other side of the wire. Hello, Microsoft!

I've tried logging in a number of times, and you won't believe me, but some servers will let me in, while others won't. Try doing smtp.ehlo() in order to find the server's hostname (by the way, you must issue EHLO at the beginning of your session, and immediately after STARTTLS).

All their servers have names BLU0-SMTP<somenumber>phx.gbl. Believe me or not, but servers with two digits in their name are OK, but those with three digits are not.

In [52]: s = smtplib.SMTP('smtp.live.com', port=587)

In [53]: s.ehlo()
Out[53]:
(250,
 'BLU0-SMTP17.phx.gbl Hello [188.134.8.114]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nTLS\nSTARTTLS\nOK')

In [54]: s.starttls()
Out[54]: (220, '2.0.0 SMTP server ready')

In [55]: s.ehlo()
Out[55]:
(250,
 'BLU0-SMTP17.phx.gbl Hello [188.134.8.114]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nAUTH LOGIN PLAIN\nOK')

In [56]: s.login(login, password)
Out[56]: (235, '2.7.0 Authentication succeeded')
In [42]: s = smtplib.SMTP('smtp.live.com', port=587)

In [43]: s.ehlo()
Out[43]:
(250,
 'BLU0-SMTP116.phx.gbl Hello [188.134.8.114]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nTLS\nSTARTTLS\nOK')

In [44]: s.starttls()
Out[44]: (220, '2.0.0 SMTP server ready')

In [45]: s.ehlo()
Out[45]:
(250,
 'BLU0-SMTP116.phx.gbl Hello [188.134.8.114]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nAUTH LOGIN PLAIN\nOK')

In [46]: s.login(login, password)
---------------------------------------------------------------------------
SMTPServerDisconnected                    Traceback (most recent call last)

Update: Hm, seems that it is a known issue with 1.0.1c.



来源:https://stackoverflow.com/questions/17011816/python-smtp-ssl-wrong-version-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!