Problems moving from System.Web.Mail to System.Net.Mail#

I recently went through the painful process of updating all our codebase to remove all warning messages after our "successful" convesion from .net 1.1 to 2.0.

After I made all the adjustments to remove all warnings, all seemd to be well.  In fact, it was going to well, as this morning I relized that I hadn't seen an exception report come through my email in a week.

Sure enough, I went into the database where I log everything and found exceptions that were not being emailed to our development team.

The exceptions that were being thrown when we tried to email were stuff like this:

Email address problemsError sending Error Report: Message: The specified string is not in the form required for an e-mail address.
Stack:   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset)
   at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
   at System.Net.Mail.MailAddressCollection.Add(String addresses)
   at System.Net.Mail.Message..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to, String subject, String body)
   at Walshgroup.Logging.ApplicationAudit.EmailErrorToDevelopmentTeam(String sErrorMessage, Int32 iLoginID) in x.vb:line 586 on machine y

Subject problemsError sending Error Report: Message: The specified string is not in the form required for a subject.
Stack:   at System.Net.Mail.Message.set_Subject(String value)
   at System.Net.Mail.MailMessage..ctor(String from, String to, String subject, String body)
   at Walshgroup.Logging.ApplicationAudit.EmailErrorToDevelopmentTeam(String sErrorMessage, Int32 iLoginID) in C:\x.vb:line 586 on machine y

It turns out that we were doing 2 things that System.Web.Mail seemed to accept, but System.Net.Mail did not.

Email Address: We were using the MS Outlook way of email concatenation (using a semicolon) to send an email to multiple people (e.g. bill@asdf.com;jack@asdf.com;pete@asdf.com).  Once I changed it to use commas, everything worked, but we still had errors related to the subject line.

What we were doing for the subject line was simply to take the first 50 characters of the email error message.  In this case, this included some CRLF.  Once those were removed the email sent w/o a problem.

For more info on these classes check out http://www.systemwebmail.com/ and http://www.systemnetmail.com/.

Categories:  |  |  |  | 
Thursday, June 01, 2006 3:33:55 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

All content © 2008, Christopher May, Inc
Open Job Positions
On this page
Google Ads
This site
Calendar
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.9.6264.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: