Reputation: 7415
We're consolidating a few applications into a new one that I'm writing. Each application has one (or more) email addresses that it processes emails from. What we'd like to do is forward each of the original email addresses to a new, centralized, address and then process the email differently based on where it was originally sent.
The server we're connecting to is Exchange 2003, and I'm using IMAP (AE.Net.Email) to get the email.
It seems like I can go through the headers and look for the Received headers, but I'm not sure that's reliable. I know some mail systems add a header specifically for this, but it doesn't seem like ours does.
So is there something I can check through IMAP that I'm just not seeing? Is there something we could do in Exchange to make sure a header gets added? Or to get the emails to different folders maybe? Is there a way to do a [email protected] similar to GMail?
Upvotes: 1
Views: 975
Reputation: 22261
You cannot tell in general when an email has been redirected, aliases, forwarded, or moved between mailboxes. In the world of SMTP, every operation which moves an email forward toward its destination is more or less equivalent to a modification to or rewrite of the SMTP envelope recipient address. Such operations can be anything from email aliases to delivery through a mailing list to user-configured forwarding rules. Some MTAs are even architected to make this fact extremely explicit: for example, the most important part of Sendmail's configuration file is nothing but a set of rules based on pattern matching and replacement that specify how the email's envelope recipient is iteratively textually rewritten.
That being said, as the email makes its way through the system, traces can be left in the headers that provide clues to what the envelope recipient used to be earlier in the process. But there are no standards and no guarantees here.
MTAs usually put some information in Received
headers that can come in handy, as you know, but not always in a predictable format. Some local delivery agents (the last step in the chain, where email is delivered into an actual mailbox) append headers like Delivered-To
to the mail before placing it in the mailbox, but this depends on the delivery agent. Mailing lists add headers like List-Id
that says which mailing list the email was delivered to before they resent the message to the individual subscribers.
There is no single place to look. The best you can do is find something that is always the same in your particular scenario and use that, or if there isn't anything, arrange for whatever script/function you're using to forward the messages to add its own bread crumb trail in the header.
Upvotes: 2