Creating Python Email (receiving) server

后端 未结 2 1635
生来不讨喜
生来不讨喜 2021-02-06 00:40

I am trying to produce a simple python script for a Linux VPS that will allow me to receive mail, (and then I can do stuff to it in python, like print it to stdout). Nothing mor

2条回答
  •  青春惊慌失措
    2021-02-06 01:38

    Yes SMTPD Module will be help full. Example code is here:

    import smtpd
    import asyncore
    
    class CustomSMTPServer(smtpd.SMTPServer):
    
        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
    
    server = CustomSMTPServer(('127.0.0.1', 1025), None)
    asyncore.loop()
    

提交回复
热议问题