Allen said:
We use Exchange Server with Outlook clients. Basically, I want to
intercept and store a copy of every email in and out as a read only copy on
a different server.
Ok, I asked because most mail systems has a way to "hook" into the
process. We write our own mail server with our own hooks, so I am not
100% familiar with the details of EXCHANGE, but I know it has it.
Lets start by understanding the mail flow.
Lets used a legend here:
MUA - mail user agent (OE, Tbird, Eudura, any mail agent, etc)
MTA - mail transfer agent, general label for receiver or sender
generally viewed as ROUTER
MSA - mail submission agent, MTA that owns the user (user login)
MDA - mail destination agent, MTA where recipient is located
From point to point, the typical topology is:
MUA --> | MSA --> MTA | --> | MDA --> [storage] | --> MUA
Sender Domain Receiver Domain
Most mail servers have MSA, MTA, MDA behavior, so you could do the
HOOK into the MSA (OUT) and HOOK into MDA (IN). In general its the
same because the ROUTER determines if its IN or OUT:
Incoming Mail --> MTA
If the mail is for a LOCAL user, the MTA is behaving as a
MDA.
Incoming mail --> MDA --> Storage for Local User
If the mail is for a REMOTE user, the MTA is behaving as a
MSA because the user must login to get authorization to
relay (route) the mail to the outside
Incoming mail --> MSA/MTA --> outgoing --> MDA
So when your Exchange receives the mail, you will know by looking at
the RECIPIENT ADDRESS(es) if they are for LOCAL or REMOTE ROUTING.
SideBar note:
There are some legal considerations of what your can do with
passthru mail (mail that your system is relaying to others,
not meant for a local user). Storage is one thing, by it can
raise privacy concerns. Using this information to your advantage
unbeknowst to the user parties involved can and has raised
legal complaints. It was against the law but the "points" of
ownership has been argue (I own the machine, it passes thru
me, therefore I haver ownership rights the mail, this was
the FACEBOOK argument last month).
What is SMTP?
When mail comes in, you have 5-6 basic commands:
EHLO or HELO sender_computer_name
AUTH scheme if the user is going to login
MAIL FROM:<sender_address>
RCPT TO:<recipient_address>
DATA
... mail transfer ....
QUIT
How you hook into the process depends on the what the mail server
offers.
M1) Hook into DATA, at the point you can capture the mail and
do something with it (even reject it)
M2) Reecive the mail, let the steps end, and the mail server
calls your "OnReceive" event
The above is the basic model, and what you need now is to find out how
to HOOK into the Exchange SMTP process is done:
Exchange Event/Sinks
I believe this uses the M2 method. It might use the M1 method. Like I
said, I know of it but not the implementation details.
Google phrases like:
Exchange SMTP Hooks
Exchange Event/Sinks
Here is one I found using C#
http://www.codeproject.com/KB/cs/csmanagedeventsinkshooks.aspx
Try googling
Exchange Event Sinks/Hooks using VB.NET
Hope the gives the basic ideas.