c# - 解析 'The specified string is not in the form required for a subject.'

标签 c# asp.net mailmessage

我有一个发送电子邮件 (MailMessage) 的类,但我收到以下错误:

"The specified string is not in the form required for a subject."

是否有方便的花花公子方法来清理字符串,还是我必须自己编写?

最佳答案

我没有亲自尝试过,但是根据this ,你只需要:

subject = subject.Replace('\r', ' ').Replace('\n', ' ');

或类似的东西。

在内部,MailMessage 类将检查主题:

if (value != null && MailBnfHelper.HasCROrLF(value)) 
{
   throw new ArgumentException(SR.GetString(SR.MailSubjectInvalidFormat));
}

因此(目前)唯一的限制恰好是 CRLF 的存在。

关于c# - 解析 'The specified string is not in the form required for a subject.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7239733/

相关文章:

c# - 使用多个存储过程将大量数据添加到数据库中

c# - 使用 JavaScriptSerializer C# 反序列化 JSON

c# - 继承和多态有什么区别?

c# - 'System.Net.ProtocolViolationException' {"You must write ContentLength bytes to the request stream before calling [Begin]GetResponse."}

c# - 使用 Javascript 添加控件并从代码隐藏中获取它们的值

c# - 如何从我的 C# 应用程序发送电子邮件?

c# - 将已发送的 MailMessage 获取到 "Sent Folder"

c# - 如何从 Windows Phone 8 应用程序发送电子邮件?

javascript - 使信号器生成的代理中心 url 动态

javascript - 使用 JQuery 进行跨域请求