1
當有人連接到這個smtp服務器時,我想發出我自己的消息。Python SMTPD庫覆蓋版本
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
如何覆蓋蟒蛇歡迎郵件,看「TEST電子郵件服務器」?