Get message size of a MapiMessage after adding a PST folder through Aspose.Email for .NET

I have a case where I am creating a new MapiMessage and setting its properties.
I have added this MapiMessage to a folder on the PST store.
Now after adding this Message, I want to know the size of this Message on the Pst store. I am not able to get this info.
I tried,

  1. Getting the size from the MapiMessage object itself through the MapiPropertyTag.PR_MESSAGE_SIZE on .Properties. Always get this as zero.

  2. Notice that MessageInfo also has a Properties property which returns the size of the message. I am getting this MessageInfo object by calling .GetContents() and comparing the EntryIdString property with the itemID.

Approach #2, will be very slow because we are doing a linear search to find the message that we just added to the PstStore.
Is there a way to fetch the email size directly from MapiMessage object.

Sample code:

Blockquote

// Assuming parentFolder of type FolderInfo already exits
var mapiMessage = new MapiMessage();
//Updates to mapiMessage

//The below lines returns nil, hence size is nil
var size = mapiMessage.Properties[MapiPropertyTag.PR_MESSAGE_SIZE]

//This works
var itemId = parentFolder.AddMessage(mapiMessage)
var messageInfoCollection = parentFolder.GetContents();
MessageInfo matchedMessageInfo;
foreach(MessageInfo msg in messageInfoCollection) {
if msg.EntryIdString == itemId {
size = msg.Properties[MapiPropertyTag.PR_MESSAGE_SIZE];
break;
}
}

Issue:
To be able to use a MailQuery to search on the folder, we need the InternetMessageId of the MapiMessage to match with the MessageId during query. But the mapiMessage object created above doesn’t have InternetMessageId nd hence we are unable to query the folderInfo for the parentFolder.

Is there a way to get the size of the email given the MapiMessage object?

Hello, @Srinidhi,

In order to get the size of the PST message, you can use the ExtractProperty method, as shown below:

var itemId = parentFolder.AddMessage(mapiMessage);

var size = pst.ExtractProperty(Convert.FromBase64String(itemId), MapiPropertyTag.PR_MESSAGE_SIZE).GetLong();

This approach has a much better performance than the use of GetContents method.

Thanks.

Hi @margarita.samodurova,

Thanks, this is exactly what I was looking for.
Another qq, which is the right property to use to set the received time of an email on the mapi message?
Looking forward to hear from you.

Thanks,
Srinidhi

I am using PR_MESSAGE_DELVIERY_TIME, but I do not see the time displayed on Outlook.
From this, PidTagMessageDeliveryTime Canonical Property | Microsoft Learn, it looks like PR_MESSAGE_DELIVERY_TIME is the correct property. Not sure why it is not getting displayed.

@Srinidhi,

Try using the PidTagClientSubmitTime property:

MapiPropertyTag.PR_CLIENT_SUBMIT_TIME

Thanks.

Hi @margarita.samodurova,

Yes,

MapiPropertyTag.PR_CLIENT_SUBMIT_TIME

works and I am able to see the date on outlook client, but wouldn’t be the wrong property to use for received date information. Reading back from the PST later would make the information wrong.

Is MapiPropertyTag.PR_MESSAGE_DELIVERY_TIME not the correct property for received date?

Thanks,
Srinidhi

Hello @Srinidhi,

but wouldn’t be the wrong property to use for received date information. Reading back from the PST later would make the information wrong.

Sorry, but I’m not sure I understand you issue. Please provide a code example for your case with the message file.

Thanks.

Hi @margarita.samodurova,

The documentation on PidTagClientSubmitTime says “Contains the date and time the message sender submitted a message”.

And for PidTagMessageDeliveryTime, it says “Contains the date and time when a message was delivered.”

I am trying to set MapiPropertyTag.PR_MESSAGE_DELIVERY_TIME with a DateTime for received messages like,

mapiMsg.SetProperty(
                    new MapiProperty(
                        MapiPropertyTag.PR_MESSAGE_DELIVERY_TIME
                    ).Descriptor, 
                    <DateTime value>
                );

I expect this to reflect in the outlook UI, but I do not see it in the UI.
But for sent time of sent items, when I set MapiPropertyTag.PR_CLIENT_SUBMIT_TIME, I can see the time displayed on the outlook UI.

So my question is, “Is PR_MESSAGE_DELIVERY_TIME the right property to set the received time of an email” because it is not reflecting in the pst file I’m creating using Aspose.Email.

Thanks,
Srinidhi

@Srinidhi,

Yes, the PR_MESSAGE_DELIVERY_TIME property is the proper one for setting the received time. It is used exactly for the time when a message is delivered to the recipient’s server.

Thanks.

Thanks for confirming @margarita.samodurova.
So this property is the same one that will be used to populate the time on the Outlook UI for received emails?

Only one of PR_CLIENT_SUBMIT_TIME and PR_MESSAGE_DELIVERY_TIME should be shown for an email on the outlook client, right?

In my case, if the PR_CLIENT_SUBMIT_TIME property is not populated, the PR_MESSAGE_DELIVERY_TIME is not displayed on the UI. Is this expected? Is there any other property that makes sense?

@Srinidhi,

Yes, that’s right.

We can’t say for sure, as it’s the Outlook behavior.

No. There are still PR_CREATION_TIME and PR_LAST_MODIFICATION_TIME properties but they don’t seem to reffer to this issue.

Thanks.