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

Source: Internet
Author: User
Tags mailmessage

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.