收到电子邮件后立即解析
我有用户发送电子邮件,其中包含一些我需要提取的文本。每个用户的电子邮件都映射到一个邮箱。我目前正在使用一个 cron 作业,每 5 分钟轮询一次邮箱(后缀),检查新消息,并将其发送到一个队列,让工作人员在其中解析它们。我有两个主要问题:
- 有没有办法可以在收到电子邮件后立即对其进行解析,而不是 轮询服务器?还有,怎么可能 我实现这个是为了可扩展吗?为了 例如,如果有 50 个传入 每秒消息数。
- 我以编程方式写入每个用户的电子邮件地址以指向 postfix 配置文件中的邮箱。是否最好创建一个包罗万象的帐户,这样我就不必写每个电子邮件地址?然而,我知道包罗万象的帐户更容易受到垃圾邮件的影响。
I have users sending emails with some text I need to extract. Each user's email is mapped to a single mailbox. I'm currently using a cron job that polls the mailbox (postfix) every 5 minutes, checks for new messages, and sends it to a queue where I have workers parse them. I have two main questions:
- Is there a way I can parse the email as soon as it's received instead of
polling the server? Also, how could
I implement this to be scalable? For
example, if there are 50 incoming
messages per second. - I'm programatically writing each user's email address to point to mailbox in the postfix configuration file. Would it be better to create a catch all account, so I don't have to write each email address? However, I know catch-all accounts are more susceptible to spam.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 管道别名 捕获电子邮件,然后使用 celery 转储放入MQ中进行处理。
Use a pipe alias to catch the email, then use celery to dump it into a MQ for processing.
是的,这可以很容易地完成。您所需要做的就是配置后缀以将电子邮件转发到脚本而不是邮箱。它实际上不必是包罗万象的,您可以配置 postfix 将特定电子邮件转发到脚本。该脚本可以用任何语言编写。我在 php 中写过几次这样的脚本。对于非常繁忙的服务器(例如每秒 50 封电子邮件)的另一种可能性是编写自己的过滤器服务器,然后配置 postfix 将每封消息传递到您的过滤器。
要将电子邮件转发到脚本,请在别名文件中添加如下一行: 路径必须指向此文件
要将电子邮件转发到过滤器,必须在 master.cf 中进行配置,有点困难。
Yes, this can be done quite easily. All you need to do is configure the postfix to forward email to a script instead of to a mailbox. It does not really have to be a catch-all, you can configure postfix to forward specific emails to a script. The script can be written in any language. I wrote such script in php a couple of times. Another possibility for a very busy server, like 50 emails per second is to write your own filter server, then configure postfix to pass each message to your filter.
TO forward email to a script, in aliases file put a line like this: the path must point to this file
To forward emails to a filter, it has to be configured in master.cf, a little more difficult.
我建议使用 Procmail 来实现此目的。它专门用于处理您收到的邮件,您可以将具有特定属性的所有邮件传递到您的应用程序。
http://www.procmail.org/
笼统地址的垃圾邮件问题通常可以解决通过监控机器上的所有邮件很容易。如果多个地址收到同一封邮件,则很有可能是垃圾邮件。
I would recommend using Procmail for this. It is specifically designed to process your incoming mail and you can pass all mail with a certain property to your app.
http://www.procmail.org/
The spam problem with catchall addresses can usually be solved quite easily by monitoring all mail on the machine. If multiple addresses recieve the same mail, than there's a high probability that it's spam.