We use the following methods to load messages from filepath or stream:
MapiMessage.FromFile();
MapiMessage.FromStream();
But when we load this message (included), we notice that it’s attachment message gets corrupted. You can open the message and see that it’s attachment msg is fine. But after MapiMessage.FromFile(), the attachment msg is messed up. If we put this message into a PersonalStorage and save it, you will see that the attachment msg is messed up.
We found a solution on the forum to load using MailMessage and then convert to MapiMessage:
MapiMessage.FromMailMessage(MailMessage.Load());
But… does this lose any MAPI property information? What is the difference when loading with MailMessage versus MapiMessage? I cannot afford to lose any MAPI information at all. Why does the attachment msg not get corrupted when we load with MailMessage?
Hi,
Thank you for using Aspose.Email.
Well, I tried to reproduce the issue as you have mentioned at my end, but could not get success. Please have a look at the following code. I have followed the same steps as you have mentioned. I extracted the embedded MSG from the first attachment and saved it to a PersonalStorage. It works fine as you can see in the attached screen shot.
Also, we recommend you to download and use this latest version of Aspose.Email for .NET v 2.0.0 in your applications.
//Open MSG in MapiMessage
MapiMessage mapiMsg = MapiMessage.FromFile("Untitled.msg");
//Extract first attachment which is another MSG
MapiAttachment mapiAttch = mapiMsg.Attachments[0];
//Save attached MSG to stream
MemoryStream memStr = new MemoryStream();
mapiAttch.Save(memStr);
//Create new PST
PersonalStorage pst = PersonalStorage.Create(@"PersonalStorage.pst", FileFormatVersion.Unicode);
// Add new folder "Inbox"
pst.RootFolder.AddSubFolder("Inbox");
// Select the "Inbox" folder
FolderInfo inboxFolder = pst.RootFolder.GetSubFolder("Inbox");
// Add attached message to "Inbox" folder
inboxFolder.AddMessage(MapiMessage.FromStream(memStr));
I’m sorry, I think we had a miscommunication.
Please do not extract the embedded .msg attachment. Please just take the original message and add it to a PersonalStorage, after loading it with MapiMessage.FromFile().
When we do this and view the .pst in Outlook, the message’s message attachment is not viewable.
Hi,
Thanks for the feedback.
After further investigation, I was able to reproduce the issue at my end with the following lines of code and latest version of Aspose.Email V2.0.0.
//Open MSG in MapiMessage
MapiMessage mapiMsg = MapiMessage.FromFile("Untitled.msg");
//Create new PST
PersonalStorage pst = PersonalStorage.Create(@"PersonalStorage.pst", FileFormatVersion.Unicode);
// Add new folder "Inbox"
pst.RootFolder.AddSubFolder("Inbox");
// Select the "Inbox" folder
FolderInfo inboxFolder = pst.RootFolder.GetSubFolder("Inbox");
// Add attached message to "Inbox" folder
inboxFolder.AddMessage(mapiMsg);
I have forwarded these details to our development team for further investigation and also requested for information about any MAPI property lose in the work around method that you are using. We will let you know here once the issue is fixed or we have any information from our development team in this regard. The issue has been logged as NETWORKNET-33376.
Thank you, Kashif.
For extra information, we notice the same problem in Aspose.Email 1.8 and 1.9 as well, so it is not a new bug.
Hi,
The issues you have found earlier (filed as NETWORKNET-33376) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.