My scenario

I'm writing a website that uses local postfix to send email to users. For any email I'm going to send I need to know if postfix has successfully delivered it (to the next-hop), or not.

What I've done so far

I correctly configured the execution of a script in case the email is bounced. To achieve this I send email with something like "info+2493@mydomain" as envelope sender address, where 2493 is the unique identifier of my mail, and configured a transport entry for info@mydomain which use a ad-hoc relay (in master.cf) that executes my script. Good

My question

How can I configure the execution of a script just like I did for bounced email for successfully delivered email instead?

And what other possibilities exist for a mail being sent besides bounced and delivered which I should care about?


For knowing status of mail delivery, postfix use DSN as state in RFC 3464. The documentation states there are 3 delivery status

  • Success (server accept the message)
  • Delayed (server can't deliver right now, but it will try again)
  • Failure (server can't deliver it, bounced back to sender)

If you send email via sendmail (for example with mail function in PHP), the default state is postfix will notify you in case there is failure or delay. If you want to be notified if message is successfully sent, add parameter -N delay,failure,success in your sendmail command. This feature documented in Postfix DSN Support and SENDMAIL(1).


To distinguish success delivery and failure, you can parsing the attachment of DSN email, especially in Delivery report section.

Here the snippet of failure delivery

Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; example.com
X-Postfix-Queue-ID: 3gPtcL5lvrzDFBC
X-Postfix-Sender: rfc822; sender@example.com
Arrival-Date: Fri,  9 May 2014 08:04:50 +0700 (WIT)

Final-Recipient: rfc822; nonexist@example.com
Original-Recipient: rfc822;nonexist@example.com
Action: failed
Status: 5.1.1
Remote-MTA: dns; example.com
Diagnostic-Code: smtp; 550 5.1.1 <nonexist@example.com>: Recipient address
    rejected: User unknown in virtual mailbox table

Here the snippet of success delivery

Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; www.example.com
X-Postfix-Queue-ID: 5936DF75D4
X-Postfix-Sender: rfc822; sender@example.com
Arrival-Date: Thu,  8 May 2014 22:58:40 +0700 (WIT)

Final-Recipient: rfc822; myrecipient@example.com
Original-Recipient: rfc822;myrecipient@example.com
Action: relayed
Status: 2.0.0
Diagnostic-Code: X-Postfix; delivery via dovecot: delivered via dovecot service
  • Good. I can successfully be notified back. But now with a "pipe" in master.cf to execute my script I cannot distinguish the delivery status (success, failed, delayed).. I don't see any suitable ${parameter} in "man pipe". If this is not feasible I will fallback to automatically check the whole DSN email. – Jack May 8 '14 at 17:04
  • 1
    @Jack Looks like you can't add parameter in your pipe program. Good luck with parsing the email body. See updated answer. – masegaloeh May 9 '14 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.