none
Stop mail item delete/move in Outlook 2003 RRS feed

  • Question

  • Hi all,

    I want to stop mail items from being deleted from outlook if that mail fulfills certain conditions. I am using Outlook 2003 and C#.

    I tried the BeforeDelete event, but that fires only when an inspector is open. How to handle deletion on the explorer using either the command buttons or the 'Del' key?

    I read the other question here, but that discusses on Outlook 2007 ribbon.

    I also want to stop these items from being moved into other folders by the user. Is there an event that can be captured and cancelled for that?

    Thanks!


    Tuesday, February 5, 2013 12:12 AM

Answers

  • Forget what I said about using Redemption's RDOFolderSynchronizer; you can trap the RDOFolder.OnMessageDeleted event.  You can't cancel it, but you can recover it.  That's the best I can come up with for Outlook 2003.  Maybe Ken or Dmitry has a better idea.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, February 6, 2013 3:53 AM
    Moderator
  • The problem with OnMessageDeleted() is it fires after the deletion, the action cannot be canceled, and the EntryID it gives you would change when the item is moved to Deleted Items if using an Exchange store. It would be the same if using a PST file, but as of Outlook 2010 that event won't even fire for a PST, only for an OST cached store.
     
    RDOItems.ItemRemove(InstanceKey) should woirk but you'd have to maintain a MAPITable of the folder items with the instance keys for comparison, and by the time that event fires the item has also been deleted. If an item is hard-deleted none of those events help much as far as possible recovery of the item.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Eric Legault [Outlook MVP]" <=?utf-8?B?RXJpYyBMZWdhdWx0IFtPdXRsb29rIE1WUF0=?=> wrote in message news:e030c2dd-b433-4f7f-94e2-384799bc6c36...
    Forget what I said about using Redemption's RDOFolderSynchronizer; you can trap the RDOFolder.OnMessageDeleted event.  You can't cancel it, but you can recover it.  That's the best I can come up with for Outlook 2003.  Maybe Ken or Dmitry has a better idea.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!


    Ken Slovak MVP - Outlook
    Wednesday, February 6, 2013 5:49 PM
    Moderator

All replies

  • The BeforeDelete event can also occur if the user selects an email and deletes it.  You just have to trap the Explorer.SelectionChange event to set and trap.  However, this is a rather complicated scenario and you have to manage a collection of wrapper classes so that you can trap every instance of a selected item or open item.  A good article that explains this is here:

    http://msdn.microsoft.com/en-us/library/ff973716%28office.14%29.aspx

    But in my opinion, code that tries to restrict what users can do with their own content is doomed for failure. They need only disable the add-in or use OWA or another device (if using Exchange) to bypass your efforts.  Only with Public Folders can you set usable permissions.


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, February 5, 2013 4:27 PM
    Moderator
  • Hi Eric,
     
    Are you sure about that? To my knowledge and according to the BeforeDelete() documentation an Inspector has to be open for BeforeDelete() to fire on the item.
     
    One can use BeforeItemMove() of course, which will fire when an item is deleted from an Explorer.Selection, assuming the event handler is instantiated.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Eric Legault [Outlook MVP]" <=?utf-8?B?RXJpYyBMZWdhdWx0IFtPdXRsb29rIE1WUF0=?=> wrote in message news:d4606957-9151-47d2-8a02-49889992c044...

    The BeforeDelete event can also occur if the user selects an email and deletes it.  You just have to trap the Explorer.SelectionChange event to set and trap.  However, this is a rather complicated scenario and you have to manage a collection of wrapper classes so that you can trap every instance of a selected item or open item.  A good article that explains this is here:

    http://msdn.microsoft.com/en-us/library/ff973716%28office.14%29.aspx

    But in my opinion, code that tries to restrict what users can do with their own content is doomed for failure. They need only disable the add-in or use OWA or another device (if using Exchange) to bypass your efforts.  Only with Public Folders can you set usable permissions.


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!


    Ken Slovak MVP - Outlook
    Tuesday, February 5, 2013 7:28 PM
    Moderator
  • Hi Eric,
     
    Are you sure about that? To my knowledge and according to the BeforeDelete() documentation an Inspector has to be open for BeforeDelete() to fire on the item.
     
    One can use BeforeItemMove() of course, which will fire when an item is deleted from an Explorer.Selection, assuming the event handler is instantiated.

    Ken Slovak MVP - Outlook

    Tuesday, February 5, 2013 7:37 PM
    Moderator
  • You're right - I stand corrected! BeforeItemMove looks optimal - good call.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, February 5, 2013 7:40 PM
    Moderator
  • Thanks guys!

    & Eric, you're right about not restricting what the user does with their local content. I will not be going down this path.

    But, it is always good to know!

    So IF I was to try and stop deletion, I would instantiate the BeforeItemMove handler on the SelectionChange event of the explorer and cancel it?

    Tuesday, February 5, 2013 10:09 PM
  • BeforeItemMove, as Ken suggested, is an event for the Folder object.  So you don't to worry about whether the item was deleted from a selection or an open item window.

    http://msdn.microsoft.com/en-us/library/office/ff869445.aspx

    Another options, for Exchange Mailboxes only, is to use Redemption's RDOFolderSynchronizer. Although it's a little complicated, it's perfect for Windows Service applications that run 24/7 without Outlook running (and can operate on multiple Mailboxes).

    http://www.dimastr.com/redemption/rdofoldersynchronizer.htm


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, February 5, 2013 10:16 PM
    Moderator
  • Thanks Eric, and Ken!
    Tuesday, February 5, 2013 10:46 PM
  • Hey guys,

    Small issue: BeforeItemMove was added from Outlook 2007?? I was looking for a solution on Outlook 2003.


    Tuesday, February 5, 2013 11:12 PM
  • Then you have no choice but to either:

    • Maintain your own collection of EntryID values for every message in a folder and monitor the contents of the folder on a timer to see which message is missing, having been deleted. You need this approach because the Items.ItemRemove event is not reliable)
    • Use Redemption

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, February 5, 2013 11:35 PM
    Moderator
  • Eric, how would I use redemption to prompt when an item is being deleted? I need to run my code BEFORE the mail item gets deleted, because I need to get some details stored in the UreProperties of that mail item.
    Wednesday, February 6, 2013 12:44 AM
  • Forget what I said about using Redemption's RDOFolderSynchronizer; you can trap the RDOFolder.OnMessageDeleted event.  You can't cancel it, but you can recover it.  That's the best I can come up with for Outlook 2003.  Maybe Ken or Dmitry has a better idea.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, February 6, 2013 3:53 AM
    Moderator
  • The problem with OnMessageDeleted() is it fires after the deletion, the action cannot be canceled, and the EntryID it gives you would change when the item is moved to Deleted Items if using an Exchange store. It would be the same if using a PST file, but as of Outlook 2010 that event won't even fire for a PST, only for an OST cached store.
     
    RDOItems.ItemRemove(InstanceKey) should woirk but you'd have to maintain a MAPITable of the folder items with the instance keys for comparison, and by the time that event fires the item has also been deleted. If an item is hard-deleted none of those events help much as far as possible recovery of the item.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Eric Legault [Outlook MVP]" <=?utf-8?B?RXJpYyBMZWdhdWx0IFtPdXRsb29rIE1WUF0=?=> wrote in message news:e030c2dd-b433-4f7f-94e2-384799bc6c36...
    Forget what I said about using Redemption's RDOFolderSynchronizer; you can trap the RDOFolder.OnMessageDeleted event.  You can't cancel it, but you can recover it.  That's the best I can come up with for Outlook 2003.  Maybe Ken or Dmitry has a better idea.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!


    Ken Slovak MVP - Outlook
    Wednesday, February 6, 2013 5:49 PM
    Moderator