到目前为止,我的代码如下:
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 服务器,但这是一个练习)