none
How can I hook into every MailItem that is going to be forwarded before the given MailItem is sent? RRS feed

  • Question

  • What I need to do is hook into every email that gets forwarded so that I can conditionally cancel it using C# and Outlook 2013.

    I saw the MailItem.Forward event and it sounded sounded promising, but I do not think its intent is applicable to my usage scenario because I want to respond to all Forward events to every MailItem in the mailbox. I think it could work if I hooked every MailItem.Forward in the inbox, but I'm not sure if that is the right way to go about this.

    The ItemSend event also looked promising, but I have failed to detect if a given MailItem is about to be forwarded. I looked at the MailItemProperties for a property that would indicate if the Forward button had been clicked for the given MailItem, but I didn't find a MailItemProperty that would tell me that.

    I saw the Inspector interface but I didn't see how I could use that for this particular need.

    What/where do I add my Delegate to handle conditional mail send cancelations?

    Friday, September 18, 2015 4:24 PM

All replies

  • Try using the PropertyAcessor of the MailItem in the ItemSend event to retrieve the MAPI property PR_LAST_VERB_EXECUTED.  This will indicate if the message is a reply or was forwarded.  I haven't tried it myself so I don't know if the property is written to the message before or after the event is fired.

    • Edited by RLWA32 Friday, September 18, 2015 4:41 PM
    Friday, September 18, 2015 4:37 PM
  • You could use the PropertyAcessor of the MailItem in the ItemSend event to retrieve the MAPI property PR_LAST_VERB_EXECUTED.  This will indicate if the message is a reply or was forwarded.

    Second to last response states this property is not a 100% sure bet that the item is being forwarded https://social.msdn.microsoft.com/Forums/vstudio/en-US/1130684a-4283-4318-bcc6-4f849cb447c0/how-to-find-out-if-outlook-mail-is-forwarded-replied?forum=vsto

    If I used native code C/C++ and COM, does that open up my options so that I could handle a Forward button click?

    Friday, September 18, 2015 5:10 PM
  • The property reveals the most recent action taken on the message.  Isn't that what you want?
    Friday, September 18, 2015 5:34 PM
  • The property reveals the most recent action taken on the message.  Isn't that what you want?

    I'm confused. Did you see the moderator comment in the link that stated there is an exception?

    "Yes, Outlook stores information only about the most recent action. In your scenario, there would be no record of a reply, unless there was an item in the Sent Items folder with the same ConversationTopic, a longer ConversationIndex, and recipients that match the original"

    Friday, September 18, 2015 5:50 PM
  • What I need to do is hook into every email that gets forwarded so that I can conditionally cancel it using C# and Outlook 2013.


    Doesn't the PR_LAST_VERB_EXECUTED do this if it is set to indicate that the message has been forwarded?
    Friday, September 18, 2015 7:02 PM
  • What I need to do is hook into every email that gets forwarded so that I can conditionally cancel it using C# and Outlook 2013.


    Doesn't the PR_LAST_VERB_EXECUTED do this if it is set to indicate that the message has been forwarded?

    If there was an item in the Sent Items folder with the same ConversationTopic, a longer ConversationIndex, and recipients that match the original, no it doesn't.
    Friday, September 18, 2015 7:36 PM
  • Items in the Sent Items folder have already been transmitted.  What does that have to do with cancelling a message that is in the process of being forwarded?
    Friday, September 18, 2015 7:56 PM
  • The point is moot.  The PR_LAST_VERB_EXECUTED property is not written to the Outlook Item that is passed to the ItemSend event.  It is written to the item from which the forward or reply originated.

    If you want to intercept forwarding of mail items you can repurpose the Forward command on the Explorer and Inspector ribbons.


    • Edited by RLWA32 Saturday, September 19, 2015 12:21 AM
    Friday, September 18, 2015 11:34 PM
  • Hello Joel,

    I saw the MailItem.Forward event and it sounded sounded promising, but I do not think its intent is applicable to my usage scenario because I want to respond to all Forward events to every MailItem in the mailbox.

    There is no need to subscribe to each email in the mailbox simultaneously. In case if you need to track user actions you may consider handling the SelectionChange event which is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. So, that you can subscribe to only selected items where users may click the Forward button.This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder.

    As for inspectors, you may consider developing Developing an Inspector Wrapper for Outlook 2010


    Sunday, September 20, 2015 8:07 AM
  • Hello Joel,

    I want to respond to all Forward events to every MailItem in the mailbox.

    There is no need to subscribe to all items in the folder.

    If you need to detect user's choice - forward, reply or reply all, you can subscribe to a corresponding event only when the Selection object is changed, i.e. user selected an item in the explorer window. The SelectionChange event is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder. So, you can subscribe to the Forward event of the MailItem class which is fired when the user selects the Forward action for an item, or when the Forward method is called for the item, which is an instance of the parent object.

    For inspector windows you may consider Developing an Inspector Wrapper .

    P.S. Looks like somebody removed my previous message, so that is the second try to post there.

    Monday, September 21, 2015 4:30 AM