当有人连接到这个 smtp 服务器时,我想发出我自己的消息。
import smtpd
import asyncore
class FakeSMTPServer(smtpd.SMTPServer):
__version__ = 'TEST EMAIL SERVER'
def process_message(self, peer, mailfrom, rcpttos, data):
print 'Receiving message from:', peer
print 'Message addressed from:', mailfrom
print 'Message addressed to :', rcpttos
print 'Message length :', len(data)
return
if __name__ == "__main__":
smtp_server = FakeSMTPServer(('localhost', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
smtp_server.close()
但是,我仍然收到以下回复:
220 Win7-PC Python SMTP proxy version 0.2
如何覆盖 python 中的欢迎消息以查看“TEST EMAIL SERVER”?