1
votes

I am working in C# and I created an .msg file (more like reconstituted one) after having read it out of Exchange and made it downloadable from a website.

However even though all that works just fine, when I try to open the .msg file, I see this error: "Cannot start Microsoft Outlook. We can't open ------.msg It's possible the file is already open, or you don't have permission to open it."

The same error occurs in Chrome or in IE, regardless of whether Outlook is open. Further it occurs even though the read permissions are permitted on the file. I have Outlook 2016 and found this link but no real help:

https://www.add-in-express.com/forum/read.php?FID=5&TID=13956

Anyone else have this issue or thoughts on how to resolve?

1
Are you sure the MSG file is not corrupted? How exactly do you create it? Can you open the MSG file in OutlookSpy (click OpenIMsgOnIStg button)?Dmitry Streblechenko
Okay on further research the challenge is in the creation of the msg. (It has that extension of the attachment in the original email). I use an EmailMessage.Bind to bind to the email itself. That works fine. Then I go through all the Attachments and check:if (attachment is FileAttachment) and it's not. Then I check if (attachment is ItemAttachment) and it is. But this plain code here does not produce the correct-sized byte file:'itm.Load(EmailMessageSchema.MimeContent); var bytes = itm.Item.MimeContent.Content;'John Linton
Bottom line is: a) the issue is really that ItemAttachment will not cast to any of the types listed for the Item Class on Microsoft.Exchange.WebServices.Data.Item and yet also: b) the "default" for a non-castable ItemAttachment var bytes = itm.Item.MimeContent.Content; seems not to work in this instance so I'm unsure how to get an accurate byte[] array out of this particular attachment. To be clear I can save it but the size is way off.John Linton
This error occurs when I try to open the corrupted file (i.e. created from the code above): "Cannot start Microsoft Outlook. We can't open .msg It's possible the file is already open, or you don't have permission to open it."John Linton

1 Answers

1
votes

It sure sounds like you really have a MIME file (extension should be .eml) rather than an MSG file (which is a binary OLE storage file). Open in Notepad your file and an MSG file created by Outlook to compare the two.