I am getting an error message when converting MSG files to Word documents (for the purpose of converting them to PDFs). The MSGs are saved from PSTs in the standard Enron test data set. The MSGs can be opened in Outlook without any problems, and Aspose.Email doesn’t have any issues with them.
My code:
private static Document ConvertEmailFileToWordDocument(string emailFilePath)
{
MessageFormat messageFormat = Path.GetExtension(emailFilePath).ToLowerInvariant() == ".msg"
? MessageFormat.Msg
: MessageFormat.Eml;
using (MailMessage msg = MailMessage.Load(emailFilePath, messageFormat))
{
using (MemoryStream mhtStream = new MemoryStream())
{
msg.Save(mhtStream, MessageFormat.Mht);
return new Document(mhtStream);
}
}
}
The error:
Aspose.Words.FileCorruptedException: The document appears to be corrupted and cannot be loaded. —> System.InvalidOperationException: Unexpected format of MIME heading.
at x4e7201a131ebc6f0.x1db3a108be0bd856.x1f490eac106aee12(String x00ea17a1f369c090, Int32& x56cdbfca406748e3, Boolean xfc076963a5541b8a)
at x4e7201a131ebc6f0.xf018334243635fc2.x06b0e25aa6ad68a9(Stream xcf18e5243f8d5fd3, Document x6beba47238e0ade6)
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
— End of inner exception stack trace —
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
at Aspose.Words.Document.x5d95f5f98c940295(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
at Aspose.Words.Document…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document…ctor(Stream stream)
at eDiscovery.Toolbox.Processor.PdfTiffConverter.PdfTiffConverter.ConvertEmailFileToWordDocument(String emailFilePath) in D:\EDT\Dev\toolbox\trunk\Source\eDiscovery.Toolbox.Processor\PdfTiffConverter\PdfTiffConverter.cs:line 248
I will attach some example MSG files.