0 votes
by (240 points)

Currently working on the retrival for a EwsMessageInfo.

I just wanted to make sure. It is not possible to call emails with the MessageId right? Because at this point I cant even access the portperty messageId, it returns a "null" value

EwsMessageCollection list = await ewsClient.GetMessageListAsync(EwsFolderId.Inbox, EwsPageView.CreateIndexed(0, numberOfEmailsToFetch));
foreach (EwsMessageInfo item in list)
   {
//Here I want to access the Mail with the messageId instead of the id
     EwsMessageInfo ewsMessage = await ewsClient.GetMessageInfoAsync(item.messageId, EwsItemFields.Envelope | EwsItemFields.Full | EwsItemFields.TextBody);
   }
Applies to: Rebex Secure Mail
by (148k points)
Update: This has been fixed in the latest release.

1 Answer

0 votes
by (148k points)
edited by

Update: This has been fixed in the latest release.


From EWS protocol's point-of-view, the message's MessageId is just one of the message headers, so if you need to access a message with a particular MessageId, you have to search for it, for example like this:

var searchResult = await _exchange.SearchAsync(EwsFolderId.Inbox, EwsItemFields.Id, EwsSearchParameter.MessageId(messageId));
if (searchResult.Count == 1)
{
    var ewsItemId = searchResult[0].Id;
    EwsMessageInfo ewsMessage = await ewsClient.GetMessageInfoAsync(item.messageId, EwsItemFields.Full);
}
else
{
    // there is no message with the specified MessageId, or there are more than one
    ...
}

As for MessageId being null in GetMessageList result (even when EwsItemFields.Envelope is specified) - this seems to be a bug, and we will fix it for the next release as well. Looks like someone confused this ID with the EWS item ID. Strangely, no one noticed until now.

...