MBF Knowledge Base

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

The following solution should allow a tool like fetchmail to separate the messages for individual users.

1.Use FEATURE(local_procmail) in your .mc file so procmail (which you must install separately) will deliver mail to the mailbox.

2.Use FEATURE(virtusertable) to create a virtual user table entry for the domain as follows:

@domain.com     domuser+%1
where domuser is the username of the mailbox you will be using. Note that "domuser" must be an actual username, *not* an alias.

It may be necessary to append "@localhost", as follows:

@domain.com     domuser+%1@localhost
3.Put the following in the respective domuser's $HOME/.procmailrc:


* ENV_TO ?? .
| formail -i "X-Envelope-To: $ENV_TO@$DOMAIN"

| formail -i "X-Envelope-To: UNKNOWN"
This will insert an X-Envelope-To header with the original envelope recipient address when the message is delivered the normal way via the virtusertable, and UNKNOWN if for some reason it was sent directly to domuser.

You may be tempted to eliminate variable ENV_TO and use $1 directly. It won't work, so don't bother.

FEATURE(local_procmail) causes sendmail to deliver email to procmail directly. A .forward file is not only unnecessary, it would prevent procmail from setting $1 with the necessary text, so don't use one.

You may need to replace formail with /usr/local/bin/formail or some such, depending on whether procmail can find it or not.