Is this a bug in implementation or is by design Invalid character in mail.Subject throws an exception

0 votes
asked Jun 13, 2016 by nklemen (150 points)


Example code:

        var mail = new Rebex.Mail.MailMessage();
        mail.Subject = "FirsName \n LastName";

throws an exception:

An unhandled exception of type 'System.ArgumentException' occurred in
Rebex.Mail.dll Additional information: Invalid character at position

Should internally by component be encoded or removed from subject or is this the correct behaviour and a developer should remove invalid characters from email subject before setting the property.

A similar post is on this address, but I didn't find the answer to the question.

What would be your recommendation for implementation of special characters?

Thank you, Klemen

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jun 13, 2016 by Lukas Matyska (61,230 points)
selected Jun 14, 2016 by nklemen
Best answer

This is done by design. Our recommendation is to not use non-printable characters (those less than 0x20), except the TAB character.

It is due to email clients, which have problems to display those characters.

Actually, it is possible to encode those characters, but it is strongly discouraged:

mail.Headers.Add("Subject", "=?us-ascii?Q?FirstName =0A LastName?=");

For example Outlook displays only "FirstName ".