你确定要断开连接?当我对后缀服务器运行上述代码时,我得到:
connect: ('server', '25')
connect: ('ip.address', 25)
reply: '220 server ESMTP Postfix\r\n'
reply: retcode (220); Msg: nserver ESMTP Postfix
connect: server ESMTP Postfix
send: 'NOOP\r\n'
reply: '250 2.0.0 Ok\r\n'
reply: retcode (250); Msg: 2.0.0 Ok
0.0531799793243
docmd 不会阻塞,服务器响应并且程序退出。因此,我在程序退出时断开连接。
如果我打开 python 命令行并执行以下操作:
>> import smtplib
>> server = smtplib.SMTP()
>> server.connect('server')
>> server.docmd('NOOP')
(250, '2.0.0 Ok')
>> ## let it sit for 5 minutes
>> server.docmd('NOOP')
(421, '4.4.2 server Error: timeout exceeded')
我的日志证实了这一点:
Oct 20 10:45:35 [postfix/smtpd] connect from unknown[ip.address]
Oct 20 10:50:10 [postfix/smtpd] timeout after NOOP from unknown[ip.address]