Postfix-如何处理传入的电子邮件?
有人知道如何在postfix中处理虚拟邮箱的传入电子邮件吗? 我正在构建Web应用程序,用户可以通过向应用程序发送电子邮件来添加新内容. 每个用户使用的电子邮件地址是自定义的(例如123456@myservice.com),并动态创建为Postfix虚拟邮箱.用户需要能够将电子邮件发送到他的自定义邮箱地址(as12145ed@myservice.com),我想处理每个传入的电子邮件,解析其内容,并使用电子邮件中的数据填充我的数据库. 我尝试使用 Postfix在队列过滤器后,但是我真正不会做的是在将电子邮件保存到其中后对其进行处理.用户虚拟邮箱文件夹.
Does anybody know how to process incoming emails for virtual mailboxes in postfix? I am building web application where users add new content by sending emails to application. Email address used for each user is custom (eg. 123456@myservice.com) and it is dynamically created as a Postfix virtual mailbox. User needs to be able to send email to his custom mailbox address (as12145ed@myservice.com) and i want to process each incoming email, parse it's contents and populate my database with data from email. I tried using Postfix After Queue filter but what i really wont is to process emails once they are saved in users virtual mailbox folder.
我可以想到两种可能的解决方案:
I can think of two possible solutions to this:
第一种可能性:您可以在Postfix中设置自定义mailbox_command
.对于Postfix收到的每封电子邮件,它将调用配置文件中定义的mailbox_command
,并在stdin
上以纯文本格式提供电子邮件.这样,您可以决定如何处理每封电子邮件.但是,您必须自己解析电子邮件的标头.您可以查看 Postfix文档,以获取有关如何使这项工作. procmail
之类的其他应用程序也可以充当mailbox_command
的角色,并帮助您处理传入的邮件.
First possibility: You can set a custom mailbox_command
in Postfix. For each email Postfix receives, it will call the mailbox_command
defined in the configuration file and provide the email as plain text on stdin
. That way, you can decide how you want to process each email. You will have to parse the headers of the email yourself though. You can take a look at the Postfix documentation for more of an idea on how to make this work. Additional applications like procmail
can also act as a mailbox_command
and help you with processing the incoming mails.
第二种可能性:使用Dovecot来存储电子邮件.您不需要启用Dovecot的POP/IMAP模块.但是,Dovecot附带了出色的doveadm
实用程序,该实用程序使您可以查询邮箱并从中读取信息.使用doveadm
,您可以自动选择新电子邮件,上周的电子邮件,阅读整个电子邮件,仅接收部分电子邮件,删除旧邮件等等.这是一个功能强大的实用程序,我在各种脚本中使用它来清除旧电子邮件或为用户提供learn-as-spam
文件夹.看看Wiki中的文档.
Second possibility: Use Dovecot to store emails. You don't need to enable the POP/IMAP modules of Dovecot. However, Dovecot comes with the fantastic doveadm
utility which allows you to query mailboxes and read from them. With doveadm
, you can automatically select new emails, emails from last week, read the whole email, just part of it, delete old messages, and so forth. It's a powerful utility, I use it in various scripts to purge old emails or provide learn-as-spam
folders for users. Take a look at the documentation in the wiki.