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, [email protected]
and [email protected]
. 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 [email protected]
and [email protected]
.
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 [email protected]
or to [email protected]
.
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
What you suggest would be against the SMTP protocol: there's legitimate reasons for adding addresses to
RCPT TO
command despite they do not exist in theTo:
orCc:
headers, i.e. RFC 5321 7.2. "Blind" Copies (emphasis is mine):The non-recommended
Apparently-to
header is controlled with optionNoRecipientAction=action
.Please note that normally the original recipient address is already in the
To:
orCc:
header. It should not be modified to the user account nameoffers
, so it's either[email protected]
,[email protected]
or hidden. Rewriting headers has become even more dangerous as it might also broke DKIM signatures. The only reasonable use case is address rewriting for mail with a local origin (user
to[email protected]
).Adding a list of all
RCPT TO
addresses would violate the protocol, but you actually simply need the single originalRCPT TO
address for the user the mail was delivered to. I don't know how to achieve this with Sendmail, but Postfix (with the default configuration) adds anX-Original-To:
header containing exactly that, and additionally aDelivered-To:
header containing the internal destination mailbox ([email protected]
).Your question is addresses by Sendmail.org FAQ 3.29
Short version: Use virtusertable and
~offers/.procmailrc
virtusertable:
~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
[email protected]
and[email protected]