Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exchange Managed API - All Returned EmailMessages Have Same Unique Id String

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

like image 276
John Chapman Avatar asked Dec 16 '22 18:12

John Chapman


1 Answers

Unique Ids are unique for EWS items. I ran across this question because I thought I was having the same issue. It turns out they are just case sensitive.

If you're saving the ids in a db, you need to make sure the collation of columns for ids are case sensitive. I changed mine from SQL_Latin1_General_Cp1_CI_AS to SQL_Latin1_General_Cp1_CS_AS. Where CI is case insensitive and CS is case sensitive.

You do not have to use the ChangeKey at all.

Please see EWS Identifiers in Exchange for more info.

One thing to keep in mind, that is covered in the link, is that ids may change when moved. This is because they are copied to the new location and the original is deleted.

like image 195
Daniel Avatar answered Dec 28 '22 07:12

Daniel