1

到目前为止,我的代码如下:

from socket import *
import ssl
msg = "\r\n smtp..."
endmsg = "\r\n.\r\n"

# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = ("smtp.gmail.com", 587)

# Create socket called clientSocket and establish a TCP connection with mailserver over SSL
clientSocket = socket(AF_INET, SOCK_STREAM);
clientSocket = ssl.wrap_socket(clientSocket, ssl_version=ssl.PROTOCOL_SSLv23)
clientSocket.connect(mailserver)

#Print server response
recv = clientSocket.recv(1024)
print recv
if recv[:3] != '220':
print '220 reply not received from server.'

我在尝试运行此脚本时收到错误消息 ssl.SSLERrror: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol。在其他时候,我收到有关服务器未及时响应的错误。

有没有人知道我做错了什么?(是的,我知道我可以使用 smtplib 来处理 smtp 服务器,但这是一个练习)

4

1 回答 1

2

端口 587 未加密。

telnet smtp.gmail.com 587

Trying 74.125.142.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP aa4sm9457625igc.15
helo test.com
250 mx.google.com at your service
于 2012-09-26T02:24:53.460 回答