"Body contains characters that are invalid for text"

0 votes
asked Jul 15, 2014 by BXH (120 points)
edited Jul 16, 2014

To whom it may concern,

So we are using Rebex (1.0.3854) in our email solution. Today we found an attachment which happens to include a single occurrence of LF (not accompanied by CR) and thus fails your Attachment constructor.

We tried base64 encoding, which Gmail adopts. In spite of that, Rebex seems to validate text before apply encoding. So we ended up with the same error information. Potentially we could also clean up user input, i.e. changing every LF into CRLF. But ideally we'd want to refrain from modifying user input.

Could you shed some light on this?

Thanks, Bangxin

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jul 16, 2014 by Tomas Knopp (58,890 points)
edited Jul 16, 2014

You can disable the invalid characters check by using the MimeOptions.AllowAnyTextCharacters option. You would be able to work with attachments which contain e.g. LF character then (as in this code snippet):

byte[] content = new byte[] { 72, 69, 76, 76, 79, 10 };
var att = new Attachment();

att.Options |= Rebex.Mime.MimeOptions.AllowAnyTextCharacters;
att.SetContent(new MemoryStream(content), "attachment.txt", "text/plain");
...