Postfix - 如何解析退回的邮件

时间:2017-12-14 04:03:22

标签: email postfix-mta postfix

我对Postfix很新。我试图谷歌关于如何处理退回邮件两天,但我的问题不是一个问题。

我想使用外部程序处理退回邮件,而AFAIK我可以执行以下步骤:

  1. 使用transport_maps属性配置main.cf

    transport_maps = hash:/ etc / postfix / transport

  2. 列出项目

    root@mail.domain.com bounce-pipe:

  3. 配置master.cf

    bounce-pipe unix - n n - - pipe user = bounce argv = / etc / postfix / mailpipe.py

  4. 创建python / ruby​​脚本以使用第三方库解析退回邮件

  5. 似乎在接收消息时调用脚本。 例如,我发送了一封不存在的电子邮件(即nonexitence@gmail.com),然后我在控制台中获得了这些信息

    mail    | Dec 14 02:15:52 mail postfix/pickup[1897]: DEB292A16D9: uid=0 from=<root>
    mail    | Dec 14 02:15:52 mail postfix/cleanup[1955]: DEB292A16D9: message-id=<20171214021552.DEB292A16D9@mail.domain.com>
    mail    | Dec 14 02:15:52 mail opendkim[146]: DEB292A16D9: no signing table match for 'root@mail.domain.com'
    mail    | Dec 14 02:15:52 mail opendkim[146]: DEB292A16D9: no signature data
    mail    | Dec 14 02:15:52 mail postfix/qmgr[1898]: DEB292A16D9: from=<root@mail.domain.com>, size=283, nrcpt=1 (queue active)
    mail    | Dec 14 02:15:52 mail postfix/smtp[1957]: connect to gmail-smtp-in.l.google.com[2404:6800:4008:c04::1b]:25: Cannot assign requested address
    mail    | Dec 14 02:15:53 mail postfix/smtp[1957]: Trusted TLS connection established to gmail-smtp-in.l.google.com[74.125.204.27]:25: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)
    mail    | Dec 14 02:15:54 mail postfix/smtp[1957]: DEB292A16D9: to=<non-existence@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.204.27]:25, delay=4.2, delays=2.6/0.02/1.1/0.52, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[74.125.204.27] said: 550-5.7.1 [103.23.147.162] The IP address sending this message does not have a 550-5.7.1 PTR record setup. As a policy, Gmail does not accept messages from 550-5.7.1 IPs with missing PTR records. Please visit 550-5.7.1  https://support.google.com/mail/answer/81126#authentication for more 550 5.7.1 information. o7si2148670pgr.491 - gsmtp (in reply to end of DATA command))
    mail    | Dec 14 02:15:54 mail postfix/cleanup[1955]: 9185A2A16DB: message-id=<20171214021554.9185A2A16DB@mail.domain.com>
    mail    | Dec 14 02:15:54 mail postfix/qmgr[1898]: 9185A2A16DB: from=<>, size=3010, nrcpt=1 (queue active)
    mail    | Dec 14 02:15:54 mail postfix/bounce[1967]: DEB292A16D9: sender non-delivery notification: 9185A2A16DB
    mail    | Dec 14 02:15:54 mail postfix/qmgr[1898]: DEB292A16D9: removed
    mail    | Dec 14 02:15:54 mail postfix/pipe[1968]: 9185A2A16DB: to=<root@mail.domain.com>, relay=bounce-pipe, delay=0.05, delays=0.03/0.01/0/0.01, dsn=2.0.0, status=sent (delivered via bounce-pipe service (20171214-021554))
    mail    | Dec 14 02:15:54 mail postfix/qmgr[1898]: 9185A2A16DB: removed
    

    问题是,存储的退回邮件在哪里或如何将它们作为参数传递给我的python脚本。退回邮件的格式应如下所示:https://github.com/sisimai/set-of-emails/blob/master/mailbox/mbox-0

3 个答案:

答案 0 :(得分:1)

格式正确的退回邮件包含许多机器可读的标头。参见例如https://en.wikipedia.org/wiki/Bounce_message#Format简要介绍了有关在何处查找更多信息的提示,包括最终相关的RFC 6522

退回邮件只是一条消息。它存储在收件人的邮箱中。例如,如果您尝试发送邮件但邮件失败,Postfix将尝试将结果反弹存储在您的收件箱中,就像向您发送任何其他传入邮件一样。

如果您只想自动处理特定用户(root或其他)的消息,Postfix已经知道如何传递给Procmail或Maildrop,这两者都可以轻松地在您的脚本上运行任意脚本传入的电子邮件,有条件地在邮件内容上(提示:从RFC中查找非常具体的DSN头字段)或无条件地。

您的问题对于您想要完成的内容非常模糊。首先,您需要了解基本的MIME结构,包括&#34; body部分&#34;的概念。以及每个身体部分如何拥有自己的标题集和一个(可能是空的)正文(有效负载),以及如何在多种不同的内容编码中表示这些标题。最近改进了Python标准email library;对于新的开发工作,请确保您的目标是3.6+(尽管从技术上讲,新实现已经存在于3.4中,而不仅仅是默认实现)。

答案 1 :(得分:0)

我找到了问题的答案如何将收到的电子邮件(邮件)传输到外部程序

我只需在安装postfix(/ etc / aliases)后配置别名

anyname: "| /tmp/your_external_script.sh"

然后更新别名:

newaliases

如果您的脚本是ruby程序,那么您可以从stdin读取所有传入的电子邮件。

看起来像这样: http://davidsj.co.uk/blog/postfix-pipe-emails-to-a-script/

答案 2 :(得分:0)

通过“stdin”(标准输入)将消息提供给您的脚本。 您的脚本需要以退出状态0退出(因为这表示“成功交付”到Postfix)。

相关问题