In the newly released version of ASP.NET 2.0, Microsoft no longer recommends using the System.Web.Mail namespace and replaces it with the new System.Net.Mail namespace. There are many new features introduced in this new library, but with them some minor bugs in the way emails are sent.
1. Sending Mail
Before discussing these small errors in detail, let's look at a sample code (we assume that you have added "using System.Net.Mail" at the beginning of the file):
MailMessage msg = new MailMessage();
msg.From = new MailAddress(" [email protected] ", "Person's Name");
msg.To.Add(new MailAddress(" [email protected] ", "Addressee's Name");
msg.To.Add(new MailAddress(" [email protected] ", "Addressee 2's Name");
msg.Subject = "Message Subject";
msg.Body = "Mail body content";
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
SmtpClient c = new SmtpClient("mailserver.domain.com");
c.Send(msg);
The above code is not much different from the implementation in the previous version, except for some minor changes in specifying the message. Instead of constructing an address yourself, you can let the system do it for you. If you specify an email address and a name, it will automatically display the following in the message:
"Person's Name" < [email protected] >
This is the "correct" format for an email address. Of course, you can further add multiple addresses to the To, CC and BCC sets in exactly the same way as above. Sending a large number of messages programmatically in this way is much easier than sending each message individually - just add multiple addresses to the BCC attribute to achieve mass mailing.
2. Existing problems
Now, let’s analyze the small errors that exist.
As mentioned earlier, this new namespace comes with some minor bugs. The first is that when you send an email, the header information is added entirely in lowercase letters. However, the RFC specification for SMTP emails does not specify how email headers should be capitalized; however, many spam filtering programs restrict email messages whose headers are not properly capitalized.
Another error has to do with priority settings - with priority settings, users can specify the importance of a message in the mail client. Because of the way the email header is formatted (converted to all lowercase), my email program (Eudora) does not recognize the corresponding priority flag and therefore does not specifically mark this email as important. Although this may seem trivial, there seems to be no obvious reason for switching to a new version of System.Web.Mail.
Therefore, I will continue to explore this problem. If I really can't find a good remedy, then I will just go back to the previous System.Web.Mail to solve the above warning problem more effectively.