Introduction
Ok, in my last blog entry you’ve seen how SMTP works. This article will delve into System.Web.Mail to see how it was built.
I’m sure when Microsoft was building the CLR framework they had many thousands of priorities on what to build first, and how to build it. Many of the namespaces and classes in the CLR framework are simply wrappers around some of the legacy COM components. System.Web.Mail is one of those namespaces.
CDOSYS and CDONTS
System.Web.Mail is unique when it is a wrapper round the COM components, because it is actually a wrapper around two COM components, CDOSYS and CDONTS. Internally, System.Web.Mail will check what the operating system it is being executed on, and then all the respective COM component. This makes troubleshooting interesting, because moving System.Web.Mail code from OS to OS can cause different exceptions to occur.
Using Anakrino, let’s look internally at what System.Web.Mail is doing.
In this first screen shot, I’ve expanded the System.Web.Mail.SmtpMail class to see some internal classes called CdoNtsHelper and CdoSysHelper.

These classes merely wrap CDONTS.NewMail and CDO.Message respectively. In fact, here is what their cctor()'s code looks like
[ CdoNtsHelper ]
private static CdoNtsHelper() {
CdoNtsHelper._helper = new LateBoundAccessHelper("CDONTS.NewMail");
}
[ CdoSysHelper ]
private static CdoSysHelper() {
CdoSysHelper._helper = new LateBoundAccessHelper("CDO.Message");
}
Ok, so now that we see System.Web.Mail is a COM wrapper, lets look at how System.Web.Mail.SmtpServer.Send() determines what class to call. Internally, the Send() method looks like
[ SmtpServer.Send() ]
public static void Send(MailMessage message) {
if (Environment.OSVersion.Platform != 2)
throw new PlatformNotSupportedException(SR.GetString("RequiresNT"));
if (Environment.OSVersion.Version.Major <= 4) {
CdoNtsHelper.Send(message);
return;
}
CdoSysHelper.Send(message);
}
From this code we can see that System.Web.Mail requires NT. It also checks to see if NT is version 4.0 or less. If so, it will use the CDONTS.NewMail object. If the OS is greater than 4.0, it uses the CDO.Message object.
So now that we know how System.Web.Mail was built, it makes troubleshooting ‘easier’. We also begin to realize some of the limitations of System.Web.Mail, and realize that it can’t outgrow the limitation of the CDONTS.NewMail or CDO.Message object.
What's Next?
In the next blog entry, I hope to discuss some of common exceptions thrown by System.Web.Mail and how we can troubleshoot them.
Questions? Comments? What do you think?