我尝试使用以下代码使用 python 启动 smtp 服务器:
import smtplib
smtp_server = smtplib.SMTP('localhost')
我收到以下错误:
File "test.py", line 2, in <module>
smtp_server = smtplib.SMTP('localhost')
File "/usr/local/lib/python2.7/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python2.7/smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python2.7/smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/local/lib/python2.7/socket.py", line 571, in create_connection
raise err
我尝试过telnet localhost 25
,telnet localhost
但他们都给出了以下错误:
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host: Connection refused
相同的 python 代码在我的另一台机器上运行得很好。
有什么建议吗?
谢谢。
更新:
我遇到问题的机器正在运行 Python 2.7.2,而代码运行良好的机器正在运行 Python 2.6.2。我不知道这是否是原因之一。