我正在寻找对电子邮件进行各种处理 - 例如。 检查标头,如果它们满足某些条件(看起来像垃圾邮件),则断开连接,或检查收件人列表并执行特殊过滤。
看起来Python的smtpd库提供了一个漂亮而简单的接口来处理收到的电子邮件。
要在完全处理消息之前对其进行处理(例如,在标头看起来像垃圾邮件的情况下删除消息),我应该使用handle_connect吗? 内部 API(process_message 除外)是否记录在某处? 示例代码在哪里?
另外,有人在生产中使用过 smtpd 吗? 关于可靠性等有什么想法吗?
关于 Twisted:我曾多次尝试采用 Twisted,并且非常喜欢延迟模型,但对于我目前的口味来说,它有点太复杂了。 我会再看一下,但现在我对非 Twisted 实现更感兴趣。
I'm looking to do various processing of email - eg. inspect the headers, and if they meet some criteria (look like spam), drop the connection, or inspect the recipient list and perform special filtering.
Looks like Python's smtpd library provides a nice and simple interface for processing the received email.
To deal with the message before it's fully processed (eg. to drop the message in case the headers look like spam), should I be using handle_connect? Are the internal APIs (other than process_message) documented somewhere? Example code anywhere?
Also, has anyone used smtpd in production? Any thoughts on reliability, etc?
Regarding Twisted: I've attempted to embrace Twisted several times and quite like the deferred model, but it's a bit too complex for my current taste. I'll give it another look, but for now I'm more interested in non-Twisted implementations.
发布评论
评论(2)
您可能需要查看 twisted 实现,因为这将使您能够与客户端进行全方位的交互。 我相信(尽管我从未在生产中使用过它)twisted 在生产环境中是值得信赖的。
You may want to look at the twisted implementation as that will give you access to the full range of interaction with the client. I believe (though I have never used it in production) that twisted can be trusted in a production environment.
另一种方法:使用 Postfix 接收电子邮件并编写 策略 Python 脚本。
Another approach: use Postfix for receiving email and write a policy script in Python.