我正在尝试创建python伪造的smtp服务器。
我尝试了旧代码,但是没有用。
该代码是针对Python 2的,但我在Python 3上运行了该代码,但仅得到打印错误并进行了修复。
我使用以下代码运行服务器:
from datetime import datetime
import asyncore
from smtpd import SMTPServer
class EmlServer(SMTPServer):
no = 0
def process_message(self, peer, mailfrom, rcpttos, data):
filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
self.no)
f = open(filename, 'w')
f.write(data)
f.close
print('%s saved.' % filename)
self.no += 1
def run():
foo = EmlServer(('localhost', 25), None)
#try:
asyncore.loop()
"""except KeyboardInterrupt:
pass"""
if __name__ == '__main__':
run()
当我尝试向自己发送电子邮件时出现此错误:
error: uncaptured python exception, closing channel <smtpd.SMTPChannel connected ('::1', 49474, 0, 0) at 0x1feaed0> (<class 'TypeError'>:process_message() got an unexpected keyword argument 'mail_options' [C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\asyncore.py|read|83] [C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\asyncore.py|handle_read_event|422] [C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\asynchat.py|handle_read|171] [C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\smtpd.py|found_terminator|386])