4

我们有一个使用 System.Net.Mail.MailMessage 和空构造函数的 Asp.Net 解决方案已经生产了 2 年多:

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;

昨天我们有一个实时站点报告异常:指定的字符串不是电子邮件地址所需的格式。我们通过将所需节点添加到 web.config 文件来修复它。

问题是:为什么这会奏效?或者它曾经工作过吗?

错误:指定的字符串不是电子邮件地址所需的格式。在 System.Net.Mail.MailAddressParser.ReadCfwsAndThrowIfIncomplete(String data, Int32 index) 在 System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index) 在 System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses , Int32& index) 在 System.Net.Mail.MailAddressParser.ParseAddress(String data) 在 System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) 在 System.Net.Mail.MailMessage..ctor ()

谢谢

编辑

  • 我们上个月从 .net 3.5 更新到了 4.0!
  • 添加了堆栈跟踪
  • 7 个月后,该错误仅出现在某些服务器上。为什么?
4

2 回答 2

3
于 2014-03-24T14:26:51.410 回答
1

Is your code set some properties after this using statement?

The default constructor has and still does work, as long as you set the properties necessary later in the code before actually triggering the send. The web.config node, typically just provides default values for those properties.

I would look into it and see if some of the properties are not getting set right and why.

于 2013-04-19T15:55:06.157 回答