We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save and load MapiMessage from stream

Hello,

we nees to save msg files from Office 365 to a PST archive.

But we want to do that using streams (saving msg file to disk previously, it works):

This works:

service.SaveMessage(msgUri, “C:\tempMsg.msg");
MapiMessage msg = MapiMessage.FromMailMessage(“C:\tempMsg.msg");

This doesn’t work:

service.SaveMessage(msgUri, memStream);
MapiMessage msg = MapiMessage.FromStream(memStream);

How to work with streams instead of temporary files?

@albertose,
Thank you for posting the query. Unfortunately, I was unable to reproduce the problem. MapiMessage.FromStream method works fine on my side. You should isolate the problem in your service.SaveMessage method or share some additional data to help us to reproduce the problem.

Can it be caused by the fact I was using the 20.12 version?
Regarding this, I tried to update to the latest version, but unfortunately this caused another issue:
The method:
EWSClient.GetEWSClient(svcUrl, username, password);
Doesn’t work anymore. The program crashes when called. How is it possible?

The exception raised by “EWSClient.GetEWSClient(svcUrl, username, password);” with the latest version is:

Mailbox information can not be read.
Folder Id: ‘msgfolderroot’; Message: Mailbox does not exist.
Folder Id: ‘calendar’; Message: Mailbox does not exist.
Folder Id: ‘contacts’; Message: Mailbox does not exist.
Folder Id: ‘deleteditems’; Message: Mailbox does not exist.
Folder Id: ‘drafts’; Message: Mailbox does not exist.
Folder Id: ‘inbox’; Message: Mailbox does not exist.
Folder Id: ‘journal’; Message: Mailbox does not exist.
Folder Id: ‘notes’; Message: Mailbox does not exist.
Folder Id: ‘outbox’; Message: Mailbox does not exist.
Folder Id: ‘sentitems’; Message: Mailbox does not exist.
Folder Id: ‘tasks’; Message: Mailbox does not exist.
Folder Id: ‘junkemail’; Message: Mailbox does not exist.

If I revert to the previous version, the 20.12, without changing anything in the code, it works.

@albertose,
Thank you for the additional information.

Please share the following:

  • comprehensive code example (msgUri and memStream variables are unknown)
  • stack trace of the error or description of the problem

Unfortunately, we recently found some problems with Aspose.Email 21.8 related to getting mailbox information. This version is not desirable for use. Our development team is preparing a new release. We apologize for any inconvenience. Please use version 21.7.

Ok, we reverted back to the version 21.7 and it works.

Regarding the issue with stream, here is a more complete code:

//***********************************
//Loop through the collection to get Message URI
foreach (string msgUri in mapiMessageList)
{
using (MemoryStream memStream = new MemoryStream())
{

	service.SaveMessage(msgUri, memStream); 

	MapiMessage msg = MapiMessage.FromStream(memStream);  

}

}
//***********************************

SaveMessage method works, saving the message into the memorystream from its URI
When we try to read back from the stream into the variable MapiMessage, the exception is:

ErrorMessage: This is not a structured storage file.
ErrorCode: -2146233079
HexErrorCode:0x80131509

@albertose,
Thank you for the additional information. I reproduced the problem with loading messages from memory streams and logged the issue with ID EMAILNET-40397 in our tracking system. Our development team will investigate this case. You will be notified when the problem is fixed.

Hi, thank you for the information.

Do you think the fix will require many days?

Where can I see the issue resolution progress?

@albertose,
The issue investigation has been scheduled for this week. According to preliminary estimates, the fix will be included in Aspose.Email 21.9 (towards the end of September).

You can see the issue status at the bottom of this forum thread.