We have an Asp.Net solution that's been in production for over 2 years using System.Net.Mail.MailMessage with the empty constructor:
using (MailMessage _mailMessage = new MailMessage()) // Exception thrown here
{
_mailMessage.From = new MailAddress(sFrom); // Setting additional properties - never gets here
_mailMessage.Body = sBody;
_mailMessage.Subject = sSubject;
_mailMessage.IsBodyHtml = true;
Yesterday we had a live site report the exception: The specified string is not in the required form for an email address. We fixed it by adding the required node to the web.config file.
The question is: Why did this ever work? or Could it have ever worked?
Error: The specified string is not in the form required for an e-mail address. at System.Net.Mail.MailAddressParser.ReadCfwsAndThrowIfIncomplete(String data, Int32 index) at System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index) at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index) at System.Net.Mail.MailAddressParser.ParseAddress(String data) at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) at System.Net.Mail.MailMessage..ctor()
Thanks
EDITS:
- We updated from .net 3.5 to 4.0 last month!
- Added stack trace
- After 7 months, the error only occurs on some servers. Why?