Much of what I've learned about IIS SMTP sinks has been largely trial-and-error, or reverse engineering. I am quite sure that the only reason for the existence of the SMTP server in IIS was to support Exchange and little else -- a guess that is only reinforced by the fact that this is no SMTP server in IIS7 included with Windows Vista (I assume it'll make a comback in Longhorn Server, though!)
In fact, I could never run our application on the SMTP server included with Windows XP anyway, because the properties exposed on the objects in the SMTP sinks were not the same between XP and Server 2003!
Anyway, this brings us back to the question asked by James: How do you work out the IP address of the SMTP client in an event sink?
It seems like a simple question, but you'll not find any documentation which says how to do it -- beleive me, I looked! However, what does help is a technique I described a while ago, where you simply loop from 1 to 20,000 or so and look for all the properties described on the MailMsgPropertyBag objects passed to your sink. These objects are basically just a mapping of numbers to values (though nobody tells you what the numbers [or their values] mean, of course!).
Using the above technique, I was able to work out that the IP address of the client maps to property #6 on the "session" parameter that is passed in. I use the IP address in my own code for doing lookups against backlists and so on. So, my HELO/EHLO sink handler looks something like this:
public void OnSmtpInCommand(object server, object session,
MailMsg message, ISmtpInCommandContext context)
{
MailMsgPropertyBag Server = new MailMsgPropertyBag(server);
MailMsgPropertyBag Session = new MailMsgPropertyBag(session);
SmtpInCommandContext Context = new SmtpInCommandContext(context);
string ip = Session.GetStringA(6); // 6 is the id of the property...
WriteLog("Client IP is: {0}", ip);
// spam check, etc..
}
Hope this helps anyone looking for the same answer as James! It's been a while since I've done a technical post like this, and it's good to be back :-)