I am using the Exchange Managed API in C# to access data from Exchange 2010. I am trying to return the unique identifiers for the email items returned so that they can be retrieved by that id later on in a separate call (i.e. first call returns all mail items and then a second call to retrieve an individual item to mark it as read, etc.). The issue that I am running into is that the string returned as the UniqueId for each mail item is the same. And on top of that, the Id for each Attachment item is also that same string.
I am using this code to retrieve the unread mail from the inbox folder.
var maxItems = 10;
var searchFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);
var itemView = new ItemView(maxItems);
FindItemsResults<Item> mailItems = service.FindItems(WellKnownFolderName.Inbox, searchFilter, itemView);
When I parse through each item in the mailItems collection, the Id.UniqueId.ToString() of every item is the same.
What am I missing here?
Thanks
After digging a bit deeper, it appears that in order to get the unique identifier for a particular mail item, you need both the UniqueId and the ChangeKey properties of the Id. When using Exchange Web Services, both of those are required.
However, in the Managed API, when you create an ItemId object, it only accepts the UniqueId property and doesn’t provide a setter for the ChangeKey property.
So, with a bit of reflection, I was able to set that property and then bind to that item.
The behavior I observed is that the “UniqueId” property could be the same for multiple items. However, the combination of the “UniqueId” and “ChangeKey” never duplicated (even if I duplicated a mail item, the two individual items had different ChangeKey values).
Why the API would not let you set the ChangeKey on a new ItemId object is beyond me.