An error occurred while sending an email via system. net. mail:
System. argumentexception: the specified string is not in the form required for a subject.
At system. net. Mail. Message. set_subject (string value)
At system. net. Mail. mailmessage. set_subject (string value)
The reflector Code shows that the suject of system. net. Mail. mailmessage calls the internal method mailbnfhelper. hascrorlf.
Internal string subject
{
Get
{
Return this. subject;
}
Set
{
If (value! = NULL) & mailbnfhelper. hascrorlf (value ))
{
Throw new argumentexception (Sr. getstring ("mailsubjectinvalidformat "));
}
This. Subject = value;
If (this. subject! = NULL) & (this. subjectencoding = NULL ))&&! Mimebasepart. isascii (this. Subject, false ))
{
This. subjectencoding = encoding. getencoding ("UTF-8 ");
}
}
}
The corresponding solution is to use the following code
Message. Subject = subject. Replace ('\ R', ''). Replace (' \ n ','')
This should have been something subject should handle, but let's handle it. This is a stinking code written by Microsoft programmers.