Creating Python Email (receiving) server

∥☆過路亽.° 提交于 2019-12-31 22:02:54

问题


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 more complex than that.

I don't want to use a 'heavy' solution or server program, I am really just after a simple python script that I can run, and is capable of receiving mail.

Will Pythons' smtpd module suffice for this task? I have heard conflicting opinions thus far. If not, what else would you suggest? Perhaps you have hacked together some code yourself?

At this stage, even projects like lamson seem too heavy (though this may be unavoidable if I cannot find a better solution).


回答1:


Pythons smtpd is sufficient.

You might also want to take a look at inbox.py and this example




回答2:


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()


来源:https://stackoverflow.com/questions/10850234/creating-python-email-receiving-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!