in

ASP.NET Weblogs

Wanta .NET ?

Dave Wanta

System.Web.Mail Explained - Part 2

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?

 

Comments

 

Jeff Julian said:

Hey mailman! I am really enjoying your blog entries. If you want to check out an article I wrote on creating your own mail client for DNJ, click here.
July 16, 2003 6:18 PM
 

Phil said:

ccol, Reflector and Anakrino are invaluable. Especially since I'm starting to take a look at Rotor source code.
July 17, 2003 6:22 PM
 

Dave Wanta said:

Yup. I've found a number of bugs with Reflector, so I've stuck with Anakrino.

Cheers!
Dave

July 17, 2003 11:57 PM
 

mike said:

Hi, Dave. Someone on the asp.net forums asks about a possible length limitation on the size of an email; he's getting an exception out of CDO when he exceeds a certain length. Perhaps this would be of interest to you w/r/t your blog entries on System.Web.Mail and CDO. The thread is here:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=268037

the question is the last entry (2nd page).

-- Mike
October 30, 2003 12:13 AM
 

TrackBack said:

January 27, 2004 9:17 PM
 

Jon R. Helms said:

Is is possible to send this through a port other than 25?
February 19, 2004 8:49 AM
 

dave wanta said:

Not in 1.0. In the 1.1 framework, they exposed the .Fields property, which gives you access to the Port.

Cheers!
Dave
February 19, 2004 9:04 AM
 

TrackBack said:

March 8, 2004 3:49 AM
 

Jon R. Helms said:

How do you access the .Fields property? I am not seeing it on the SMTPServer object and I am using Framework 1.1.
March 17, 2004 5:53 PM
 

Dave Wanta said:

then something is wrong with your 1.1 install, because it's there.

What is the compiler error message?

Cheers!
Dave
March 17, 2004 6:41 PM
 

Jon R. Helms said:

Ok, where exactly is this .Fields property, the MSDN library doesn't even list a Fields member on the SMTPMail object of which SmtpServer is a property. If you are referring to the .Fields property of the MailMessage object a sample would be VERY appreciated. The error is that "Fields is not a member of string", string is of course the datatype of the SmtpServer property.
March 18, 2004 8:15 AM
 

Dave Wanta said:

March 18, 2004 8:33 AM
 

Jon R. Helms said:

Thanks for the link, I got it working.

MailMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = NewServerPort
March 18, 2004 9:21 AM
 

Dave Wanta said:

Awesome!

cheers,
Dave
March 18, 2004 9:27 AM
 

Kirk Carter said:

Thanks for having the port number tip. It saved my bacon!
April 8, 2004 5:29 PM
 

dan said:

Does any one know how to format names
(in the CC section as well) so that group wise reads them as if they were sent internally?
July 29, 2004 12:25 PM

Leave a Comment

(required)  
(optional)
(required)  
Add