Loading MSG file failed

Hello,

ich we try to load the attached MSG file (long name with spaces and some special, but allowed, characters), folloing error occurs:

System.InvalidOperationException: ‘Incorrect message format specified in the options: Msg’

Outlook, the Mail can be opened.

We load the mail in the following way:
var mailMessage = MailMessage.Load(InputFile, new MsgLoadOptions { RemoveSignature = true })

Mail.zip (49,5 KB)

Kind Regards,
Andy

Hello @AStelzner,

Thank you for contacting the support forum.

You have provided a file that has a .msg extension, but the actual format is eml (just review its contents in any text editor).

To safely load the file, you can either use the Load method without the LoadOptions parameter,

var mailMessage = MailMessage.Load(fileName);

or use DetectFileFormat to determine the actual format of the message:


if (FileFormatUtil.DetectFileFormat(fileName).FileFormatType == FileFormatType.Eml)
{
    var mailMessage = MailMessage.Load(fileName, new EmlLoadOptions{RemoveSignature = true});
}

if (FileFormatUtil.DetectFileFormat(fileName).FileFormatType == FileFormatType.Msg)
{
    var mailMessage = MailMessage.Load(fileName, new MsgLoadOptions{RemoveSignature = true});
}
1 Like

Thanks, it works :slight_smile:

Good. If you have any further questions, feel free to ask.