Addin Event BeforeItemMove gets deleted by EWS or OWA Move Operation RRS feed

  • Question

  • Hi,

    I want to disallow users to move or delete emails from their inbox. Currently I use a .NET addin which sets the "BeforeItemMove" event for the affected folders and always sets "Cancel = true;" and it is working fine.

    All users are able to move emails with a custom button. Since the moving should be done by another user account with more rights, I use the "Microsoft.Exchange.Webservices" EWS API to create a second connection to Exchange with a different user and to move the email. This is also working fine. (I convert the EntryID to EwsID)

    After the inbox email has been moved to a subfolder via Ews (with a Outlook addin Button) the "BeforeItemMove" events are gone, and the user can move emails again freely. I can set the event handlers again, but than they won't always fire or stop working after some tries.

    The same happens when user A works in Outlook with mailbox Z and user B accesses the same mailbox Z with Outlook Web Access (OWA), after moving a mail the already set and working eventhandlers are gone or do not fire anymore.

    User A has full rights to mailbox Z, User B is owner of mailbox Z.

    If user B (owner) uses Outlook and OWA at the same time, everything works and the events won't get lost.

    But I need two different users, because one user should not be able to move mails by himself, another user account should be used for that.

    We use Exchange 2016, Outlook 2013, .NET 4 and the latest Ews assemblies from NuGet.

    Why does Outlook loose a event when a mail gets moved by EWS or OWA? I don't get it.

    Thanks and regards

    • Edited by Matthew312 Tuesday, April 19, 2016 12:37 PM
    Tuesday, April 19, 2016 12:36 PM

All replies

  • Hello Matthew,

    What code exactly do you use for subscribing to the BeforeItemMove event?

    > Why does Outlook loose a event when a mail gets moved by EWS or OWA?

    Is it fired for other items in the folder (not moved using EWS)?

    Have you tried using Extended MAPI notifications (a low-level code). For example, you can use any third-party wrapper around that API.


    Tuesday, April 19, 2016 3:59 PM
  • Hi Eugene,

    thank you for your answer!

    Before moving the item via EWS every mail in my folder and subfolder that gets moved or deleted fires the BeforeItemMoveEvent correctly. After moving one item via EWS none of the remaining items fires the Event in Outlook anymore. The same occurs with a move via OWA.

    I assign the eventhandlers like this:

    (... snip ...)
    rootFolder.BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
    (... snip ...)
    private void Folder_BeforeItemMove(object Item, Outlook.MAPIFolder MoveTo, ref bool Cancel)
    	if (true)
    		Cancel = true;
    		MessageBox.Show("Not allowed");

    Which third-party wrapper do you recommend? Do they offer own events too?

    Thanks and Regards

    • Edited by Matthew312 Wednesday, April 20, 2016 8:22 AM
    Wednesday, April 20, 2016 8:21 AM
  • A quick followup, it seems any EWS operation on a account deletes events in Outlook sessions with the corresponding folders.

    I added a new rule with UpdateInboxRules and CreateRuleOperation on the account and after that the Outlook BeforeItemMove events were gone too.

    edit: After restarting Outlook all events work fine again, but If I receive a new mail and the EWS rule fires, the events are broken again. ???

    I also tried the "ReliableFolderMoveEvent" registry key for Office 2007/2010 but it does not help.

    The problem occurs while using Outlook as owner user of the mailbox and as additional mailbox with another user.
    • Edited by Matthew312 Wednesday, April 20, 2016 12:04 PM
    Wednesday, April 20, 2016 9:08 AM
  • Hi Matthew312,

    is your issue get solved? or you are still facing a problem with that?

    if your issue get solved would you like to share the solution with our community so that if some other member have same issue like you can also get the solution by your post.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 29, 2016 6:49 AM