MailAddress: Invalid character was found in the mail header

I use MailAddress to create a fax. We use a system called SatisFAXtion v 8.6. To provide a cover page for sending faxes, I can add the template location to mail.TO.

The format is as follows:

12125551234^template=cp\\ FAXReportCover.rtf@fax.ourcompanymail.com 

It works fine when compiling, but I need two backslashes, so I added two more escape characters.

When I run the program, I get an exception:

 Message: An invalid character was found in the mail header: StackTrace: at System.Net.Mail.MailAddressParser.ParseLocalPart(String data, Int32& index, Boolean expectAngleBracket, Boolean expectMultipleAddresses) at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index) at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data) at System.Net.Mail.MailAddressCollection.ParseValue(String addresses) at System.Net.Mail.MailAddressCollection.Add(String addresses) at System.Net.Mail.Message..ctor(String from, String to) at System.Net.Mail.MailMessage..ctor(String from, String to) 

Is there a way to insert a backslash in an email address in a MailAddress object?

+6
source share
3 answers

From Wikipedia :

The restrictions for special characters are that they should only be used when enclosing between quotation marks, and that 3 of them (The space, backslash \ and quotation mark "(ASCII: 32, 92, 34)) must also be preceded by a backslash dash \ (for example, "\\\" ").

Therefore, I do not think your email address is valid, since the backslash does not appear between quotation marks.

If you could change the address to something like 12125551234^template="cp\\" FAXReportCover.rtf@fax.ourcompanymail.com , I think that everything will be fine.

+4
source

A few years ago, I found a workaround for a similar problem. The problem was with the DisplayName parameter in the MailAddress constructor.

Perhaps this will also help:

http://netpl.blogspot.com/2008/09/smtpclient-exception-invalid-character.html

+3
source

I got this error, if this change was changed to "network" - then the error was resolved. (My understanding is to enable the specified pickupdirectory option, the -encoding utf-8 (base64) header gave an error)

Hope this helps

0
source

Source: https://habr.com/ru/post/914232/


All Articles