首页 > 解决方案 > 如何将简单的 smtp 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()

从同一台机器上没问题,可以接收和读取邮件,从同一局域网中的其他电脑我无法连接。怎么了?谢谢大家。

标签: pythonemailsmtpd

解决方案


推荐阅读