How to pass original recipient by Postfix to Procmail

Just like old fashioned mail letters, email has two different sets of address information: the envelope address (like the addresses printed on the outside of an envelope) which are used by the SMTP servers to route and deliver the email to the intended recipient, and message headers which are part of the mail message.

The SMTP envelope contains among other information the RCPT TO: destination of the email message in a SMTP transaction.

The message headers (in the DATA payload of an SMTP message) are mostly only read and interpreted by the user in his mail client/webmail, just like date and the address attached to a salutation at the start of a physical letter. Those are not used for routing the email message1 to its destination. The To: header is part of those (untrusted) message headers and can even be completely different from the address on the enveloppe.

Unlike the post office, SMTP usually throws away most of the enveloppe before it hands the message to the user.

As far as I know Postfix adds the SMTP envelope recipient address to the message headers as the X-Original-To: header. X-Original-To: is the address it received as the RCPT TO: in the SMTP dialog.

It usually also adds a second header, the Delivered-To: header, which contains the email address of the Mailbox Postfix actually delivers the message to. That could be different from the X-Original-To: because there can be several levels of aliases, virtual addresses and other address expansion that take place. (See: http://www.postfix.org/ADDRESS_REWRITING_README.html)

You should be able to rely on either of those headers for your procmail recipes


Footnotes:

  1. The CC: (and similarly the BCC:) headers are message headers that normally should be interpreted by a MUA when sending the message and which are converted to additional RCPT TO: envelope addresses, they are normally not processed2 by the SMTP server.

  2. Note that Postfix does process the Bcc and some other message headers, in a fashion, as by default the cleanup will remove message headers that shouldn't be included by a MUA in messages: Bcc, Content-Length, Resent-Bcc, Return-Path.