Search code examples
c#openpop

ToMailMessage() - An invalid character in Header


I have got a console application that processes emails in a mailbox using OpenPOP, it is failing on one email with the following exception

An invalid character was found in the mail header: '\u007f

The code it is calling is the following

            MailMessage _testMail = emailFile.ToMailMessage();               
            _testMail.BodyEncoding = Encoding.UTF8;
            _testMail.Subject = _testMail.Subject + " Issue ID: " + callid;

it is failing when it calls emailFile.ToMailMessage() and help would be appreciated


Solution

  • \u007f is the DELETE character - that seems to be invalid in your context. You might have to strip unwanted characters from your input before calling .ToMailMessage.