Sendmail – How to Add Envelope Recipient Header to Inbound Emails

rulessendmailsmtp-headers

Disclaimer: I have read some of the questions and articles here and elsewhere which deal with Sendmail rewriting headers. I haven't found an answer to the question below because the other question mostly relate to rewriting headers (instead of adding them), and nearly all of them relate to outbound messages and the envelope sender (instead of the envelope recipient).

Having said this:

I am running a mail server, using Sendmail 8.14.4 under Debian jessie.

There are some email recipient addresses which are mapped to the same O/S user account. When the respective O/S user reads the messages, he can't determine to what email address the messages originally have been sent.

Therefore, I would like to have Sendmail add a custom header containing the envelope recipient(s) to all inbound email messages.

I think I could better explain my problem by example:

Suppose I have two email addresses, offer1@example.com and offer2@example.com. Both are mapped to the O/S user account offers. This works so far: The O/S user offers, when fetching his email, gets all messages sent to offer1@example.com and offer2@example.com.

The problem now is that he can't determine to which email address each message originally has been sent. That means: Although he is seeing all messages which have been sent to both email addresses, he can't tell if a certain message has been originally sent to offer1@example.com or to offer2@example.com.

Therefore, I would like to add a custom header to each inbound message, perhaps something like that: X-Envelope-Recipient: <Original envelope recipient>.

What would be the easiest way to do this?

Once upon a time, I have written some simple custom rules for Sendmail. But nearly 15 years have passed since then, so I'd like to avoid that, and thus I hope that there is an easy solution or that somebody could point me in the right direction. To be honest, writing a milter to solve my problem currently seems easier to me than re-learning Sendmail's rule syntax …

EDIT 1

As requested by @AnFi, here is the local mailer definition from sendmail.cf:

Mlocal,         P=/usr/lib/sm.bin/mail.local, F=lsDFMAw5:/|@qPSXnz9, S=EnvFromSMTP/HdrFromL, R=EnvToL/HdrToL,
                T=DNS/RFC822/SMTP,
                A=mail.local -l -h inbox

Best Answer

Your question is addresses by Sendmail.org FAQ 3.29

3.29 How can I add a header specifying the actual recipient when having multiple users in a virtual domain go to a single mailbox?

Short version: Use virtusertable and ~offers/.procmailrc

virtusertable:

offer1@example.com  offers+offer1
offer2@example.com  offers+offer2

~offers/.procmailrc should get "plus detail" in $1.
OR
You can use $h (set to +detail) in custom headers

Warning: you will get/process two copies of a message addressed to both offer1@example.com and offer2@example.com

Related Topic