6

I am using MailAddress to create a fax email. We are using system called SatisFAXtion v 8.6. To provide a cover page for faxing I can add a template location to the mail.TO address.

The format looks like this:

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

When compiling it works fine but I need two backslashes so I added two more as 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 backslashes in an email address in MailAddress object?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Boguslaw Buczek
  • 93
  • 1
  • 1
  • 6

3 Answers3

4

From Wikipedia:

The restrictions for special characters are that they must only be used when contained 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 \ (e.g. "\ \\"").

Therefore, I don't think your email address is valid as the backslashes are not contained between quotation marks.

If you could change the address to something like 12125551234^template="cp\\"FAXReportCover.rtf@fax.ourcompanymail.com I think it would be ok.

RB.
  • 36,301
  • 12
  • 91
  • 131
3

Years ago I found a workaround over a similar issue. The issue was in the DisplayName parameter in the constructor of MailAddress.

Maybe it will help you too:

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

xpereta
  • 692
  • 9
  • 21
Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • Beware, your workaround is for the displayName parameter, not the address parameters. – xpereta Dec 02 '13 at 09:18
  • I have removed the downvotes and improved the answers instead. Although they do not address the exact problem of the question they may be useful to future users. – xpereta Dec 03 '13 at 10:22
  • To make it a better answer, please include the solution, not just a link to another website. – xpereta Dec 03 '13 at 10:32
  • @xpereta: This is not just a website, it's my blog. Anyway, thanks for the insight and the correction. – Wiktor Zychla Dec 03 '13 at 12:14
  • I know it's your blog and you care about it, but for future users it's an external website. The answer here should contain the explanation to solve the question if possible. – xpereta Dec 03 '13 at 12:40
  • @xpereta: true. I woudn't even comment if this was a fresh question. However, it's a year and a half old, the OP didn't give any feedback on that and frankly, I forgot about it, just as I forgot dozens of other answers I provide and there is no feedback. – Wiktor Zychla Dec 03 '13 at 13:20
0

I received this error when if this is modified to "network" --- then error got resolved. ( My understanding is - Incase of specified pickupdirectory option, the header -encoding utf-8 (base64) was giving error )

Hope it helps

HydPhani
  • 592
  • 6
  • 13