Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a class that sends an Email (MailMessage) but I get the following error:

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

Is there a handy dandy method to sanitize the strings or do I have to write my own?

like image 564
Matt Avatar asked Aug 30 '11 07:08

Matt


1 Answers

I haven't personally tried it, but according to this, you only need:

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

or something equivalent.

Internally, the MailMessage class will check the subject with:

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

So the only limitation (for now) happens to be the presence of CR or LF.

like image 120
Christian.K Avatar answered Sep 20 '22 15:09

Christian.K