Body contains characters that are invalid for text.

0 votes
asked Sep 22, 2010 by David Duffett (120 points)
edited Mar 24, 2011

When constructing an email message I set both the BodyHtml and BodyText properties of the MailMessage.

The other day I received an exception report with the following stack trace:

Rebex.Mime.MimeException: Body contains characters that are invalid for text. at Rebex.Mime.MimeEntity.CheckTransferEncoding(MailBodyStream body, ContentType ct, ContentTransferEncoding cte) at Rebex.Mime.MimeEntity.SetBody(MailBodyStream body, ContentType ct, ContentTransferEncoding cte, String name) at Rebex.Mime.MimeEntity.SetContentInternal(String text, String mediaType, Encoding charset, ContentTransferEncoding transferEncoding) at Rebex.Mime.MimeEntity.SetContent(String text, String mediaType) at Rebex.Mail.AttachmentBase.SetContent(String text, String mediaType) at Rebex.Mail.MailMessage.set_BodyText(String value)

This was manually fixed by removing the offending character, however, should I be encoding the text before setting this property? If so, to what encoding?

Does BodyText not handle unicode characters?

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Sep 23, 2010 by Lukas Pokorny (102,210 points)
edited Sep 23, 2010

BodyText/BodyHtml does handle Unicode characters. However, some not characters are not allowed to be present in text parts of mail messages (by the MIME standard) - for example, the binary 0 character and CR/LF characters (10 and 13) unless they are a part of end-of-line sequence.

In the current version of Rebex Mail, BodyText and BodyHtml property setters should automatically remove these characters, so it looks like you are using an older version. Is this correct? The new functionality has been available since Rebex (Secure) Mail 1.0.3588.0.

commented Sep 23, 2010 by David Duffett (120 points)
Aah. We're using Rebex Mail 1.0.3134.0.
commented Oct 1, 2010 by Martin Vobr (12,940 points)
Than upgrade to the more current version would probably solve it. If the version 3588 were released during 12 month after your purchase you are eligible to free upgrade. If not you can upgrade to the current version for about 1/3 of full license price. Please send your order number to support@rebex.net for assistance.
...