当有人连接到这个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”?
答案 0 :(得分:0)
只做
smtpd.__version__ = "TEST EMAIL SERVER"
某处(可能是在导入语句之后)。