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/.