Question

This is one of those hard to explain questions. I've tried my best below, hopefully it is clear what I mean.

Emails are coming in to an address (foo@example.com), and are being forwarded to another email address (bar@subdomain.example.com). The second email address further pipes the email to a simple script, but the script needs to actually know the second email address as it provides meta-data that is crucial to sorting the message (that is, the script gets piped any email sent to *@subdomain.example.com, and it needs to see that it got forwarded to bar@subdomain.example.com in order to correctly process the incoming message).

Originally, I thought that the virtual alias used to forward messages from foo@example.com to bar@subdomain.example.com would update the envelope-to header, but it remains unchanged the same. None of the other headers nor the "received" line reflect that the message was forwarded. My theory is that maybe the pipe instructions for *@subdomain.example.com can be updated to somehow pass the actual address on to the script, but I am not sure how.

For reference, I have included a few examples below:

Headers, after being forwarded:

From sender@example.com Sun Dec 11 19:53:40 2011
Envelope-to: foo@example.com
Received: ...
Subject: Test 6

The valias file for subdomain.example.com (/etc/valiases/subdomain.example.com):

*: "|/home/user/example_script.x.php"
Was it helpful?

Solution

And I answered my own question. It turns out, the recipient is accessible in an environment variable. In my case, since I am using PHP, I can just use the following variable:

$_ENV['RECIPIENT']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top