Postfix通知发送

我的场景

我正在写一个网站,使用本地postfix发送电子邮件给用户。 对于我要发送的任何电子邮件,我需要知道postfix是否已经成功发送(到下一跳)。

到目前为止我所做的

我正确地configuration了脚本的执行情况,以防电子邮件被退回。 为了达到这个目的,我发送了一封包含“info + 2493 @ mydomain”作为信封发件人地址的电子邮件,其中2493是我的邮件的唯一标识符,并为info @ mydomainconfiguration了一个使用ad-hoc中继的传输条目.cf)执行我的脚本。 好

我的问题

我怎样才能configuration脚本的执行,就像我反弹电子邮件成功传递电子邮件呢?

还有什么其他可能性的邮件被发送,除了反弹和交付,我应该关心?

为了了解邮件发送的状态, postfix在RFC 3464中 使用DSN作为状态。 该文件指出有3个交付状态

  • 成功(服务器接受消息)
  • 延迟(服务器现在不能提供,但它会再试一次)
  • 失败(服务器无法发送,反弹回发件人)

如果您通过sendmail发送邮件(例如使用PHP中的邮件function ),默认状态是postfix会在发生故障或延迟的情况下通知您。 如果您希望在消息成功发送时收到通知-N delay,failure,success在sendmail命令中添加参数-N delay,failure,success 。 此functionlogging在Postfix DSN支持和SENDMAIL(1)中 。

UPDATE

为了区分成功交付和失败,您可以parsingDSN email的附件,特别是在Delivery report部分。

这里是失败交付的片段

 Content-Description: Delivery report Content-Type: message/delivery-status Reporting-MTA: dns; example.com X-Postfix-Queue-ID: 3gPtcL5lvrzDFBC X-Postfix-Sender: rfc822; [email protected] Arrival-Date: Fri, 9 May 2014 08:04:50 +0700 (WIT) Final-Recipient: rfc822; [email protected] Original-Recipient: rfc822;[email protected] Action: failed Status: 5.1.1 Remote-MTA: dns; example.com Diagnostic-Code: smtp; 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual mailbox table 

这里是成功交付的一小部分

 Content-Description: Delivery report Content-Type: message/delivery-status Reporting-MTA: dns; www.example.com X-Postfix-Queue-ID: 5936DF75D4 X-Postfix-Sender: rfc822; [email protected] Arrival-Date: Thu, 8 May 2014 22:58:40 +0700 (WIT) Final-Recipient: rfc822; [email protected] Original-Recipient: rfc822;[email protected] Action: relayed Status: 2.0.0 Diagnostic-Code: X-Postfix; delivery via dovecot: delivered via dovecot service