我有一个发送电子邮件 (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));
}
因此(目前)唯一的限制恰好是 CR
或 LF
的存在。
关于c# - 解析 'The specified string is not in the form required for a subject.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7239733/