none
[E2010] [EWSMA] [C#] [Windows]: How to get the InternetMessageID of deleted Items RRS feed

  • Question


  • we are using SyncFolderItems to synchronize folders (emails, IPM.Notes). When an item gets deleted we only get the itemID from the EWSMA in the delete event (changeType=Delete). Now sometimes we are not aware of the itemID (the deletion is faster than the sync of a create event).

    in this situations we would need InternetMessageID to find the deleted item. Also, the create event itself would help alot, but we only get the deletion.

    thanks in advance....

    Gregor Stefka

    Thursday, February 13, 2014 9:40 AM

Answers

  • With SyncFolderItems the only thing you will get back from Exchange is the ItemId of the deleted Item. Its really a limitation of this operation which is more designed to help you sync the contents of the folder not the status of particular items if they are moved in the Mailbox.

     If you want to track email events then Pull Notifications are a better option. In 2010 and 2013 if you have Single Item Recovery enabled then when a user deletes an email (not matter the method they use) it doesn't get deleted rather it's moved to the Dumpster v2 Folders in a mailbox. So with Pull notifications you can just listen to the MoveEvents on the Inbox which will give you the ItemId for Item once its moved to the Recoverable Items Folder (or if its soft deleted the DeleteItems folder or if its moved the folder its moved into). eg

                Folder Deletions = Folder.Bind(service,WellKnownFolderName.RecoverableItemsDeletions);
                EventType[] evEvents = new EventType[] { EventType.Copied, EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved, EventType.NewMail };
                PullSubscription pullsub = service.SubscribeToPullNotificationsOnAllFolders(1440, "", evEvents);
                GetEventsResults gEvents =  pullsub.GetEvents();
                foreach (ItemEvent itmEvent in gEvents.ItemEvents) {
                    if (itmEvent.EventType == EventType.Moved)
                    {
                        Console.WriteLine(itmEvent);
                        Item it = Item.Bind(service, itmEvent.ItemId);
                        Console.WriteLine("Item : " + it.Subject);
                        if (it.ParentFolderId.UniqueId == Deletions.Id.UniqueId)
                        {
                            Console.WriteLine("Moved to Recoverable Items - Deleted Items");
                        }
                        else
                        {
                            Folder fld = Folder.Bind(service, it.ParentFolderId);
                            Console.WriteLine("Moved to : " + fld.DisplayName);                        
                        }                  
    
                    }
                }
    Cheers
    Glen


    Friday, February 14, 2014 4:39 AM