How to properly store EwsItemId in the database for later use

0 votes
asked Mar 9 by abarref (250 points)

I'm using Rebex to send an email like this:

        // Get EwsItemId
        ewsItemId = _ewsClient.StoreMessage(EwsFolderId.Drafts, mailMessage);

        _ewsClient.SendMessage(ewsItemId, ewsFolder.Id);

Then I grab the ewsItemId and store it as a string in the database. Something like:


Then later I get this Id and do:

        EwsItemId ewsItemId = new EwsItemId(itemId);

        EwsItemInfo item = _ewsClient.GetItemInfo(ewsItemId);

and I get the following exception:

Rebex.Net.EwsException: The specified object was not found in the store., Cannot get ID from name (ErrorItemNotFound).

I know that actually the EwsItemId is composed by an Id and a ChangeKey. Must I also store the ChangeKey? What's the best approach to store the EwsItemId in the database for later use?

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Mar 12 by Pavel Matyska (10,460 points)
selected Mar 12 by abarref
Best answer


you store the EWS Id correctly. But when you send the stored message, it is moved to another folder and its id is changed, not only its change key. So your id of the stored message is not valid at that point.
Unfortunately, Exchange server do not include new Id of the sent message that is moved/created to your folder with ewsFolder.Id.
Sending the message and using Sent Items folder doesn't help neither. Your only option is to find the sent message in your folder using Ews.Search(...) method to get new id of the sent message and store this in your database for later use.