The error most likely occurred because the e-mail message's subject header was not properly encoded and could not be parsed by Rebex Mail.
The following code reproduces the same error:
string source = "Subject: =?us-ascii?Q?This_is_wrong_=_?=\r\n\r\nText";
MailMessage mail = new MailMessage();
mail.Load(System.Text.Encoding.ASCII.GetBytes(source));
string subject = mail.Subject;
This produces an exception when accessing the MailMessage
object's Subject
property.
Workaround 1: Prior to loading the message, enable IgnoreUnparsableHeaders
option by adding the following line:
mail.Options |= MimeOptions.IgnoreUnparsableHeaders;
If the message was not loaded from a file, stream or byte array but retrieved from an Imap or Pop3 object instead, a corresponding IgnoreUnparsableHeaders
is available for Imap.Options
and Pop3.Options
property (enable ImapOptions.IgnoreUnparsableHeaders
or Pop3Options.IgnoreUnparsableHeaders
, respectively).
Workaround 2: If accessing MailMessage.Subject
fails, use the content of MailMessage.Headers["subject"].Raw
instead. If possible, please let us know the content of this property, it might help us to determine what exactly is going on and perhaps enhance the parser to handle some kind of broken input as well.