如何将简单的smtp python服务器绑定到lan?

2024-10-01 15:32:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一个python smtp服务器来接收多个dvr警报邮件,存储它并处理它。 我环顾四周,发现了以下简单代码:

   from datetime import datetime
   import asyncore
   from smtpd import SMTPServer

   class EmlServer(SMTPServer):
       no = 0
       def process_message(self,peer, mailfrom, rcpttos, data, **kwargs):
           adesso=datetime.now().strftime('%Y%m%d%H%M%S')
           print(adesso)
           print(data)
           return
           filename=alarm.eml
           with open(filename, 'w') as f:
                f.write(data)
           self.no += 1
           return None

    def run():
        foo = EmlServer(('0.0.0.0', 1025), None,decode_data=True)
        print(repr(foo))
        try:
            asyncore.loop()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            print(repr(e))


    if __name__ == '__main__':
        run()

从同一台机器可以接收和读取邮件,从同一局域网内的其他pc我无法连接。发生了什么? 谢谢大家


Tags: nofromimportselfdatadatetimereturndef

热门问题