none
Detecting Outlook Context menu selection RRS feed

  • Question

  • I am writing a spam filter for Outlook. I want to be able to detect when an email is sent to the junk folder, so I need to know how to detect which menu item is selected from a context menu. I can already tell when the context menu is opened, and closed, but can't figure out how to tell which menu item was selected. I am using this code.

    outLookApp.ContextMenuClose +=

    new ApplicationEvents_11_ContextMenuCloseEventHandler(outLookApp_ContextMenuClose);

    void

     

    outLookApp_ContextMenuClose(OlContextMenu ContextMenu)

    {

     

    if (ContextMenu == OlContextMenu.olItemContextMenu)

    {

    // this is for testing purposes.
    textBox1.Text = ContextMenu.ToString() +

    Environment.NewLine;

    }

    }

    Thursday, August 13, 2009 2:24 PM

Answers

All replies

  • You might find this thread helps as you will need to use the selected item

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/cdfd50c3-6627-4494-815c-5157ef01b766

    Regards


    Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
    Thursday, August 13, 2009 2:52 PM
    Moderator
  • After reading the article, it seems the the MailItem.Actions should contain the menu item selected in the context menu, however if it is in there, I sure can't find it. Any help would be great appreciated, that shows the exact code required. Here is the code I am using:

     

    private void Explorer_SelectionChange()

    {

     

    foreach (object selectedItem in EX.Selection)

    {

     

    MailItem item = selectedItem as MailItem;

     

    if (item != null)

    {

    textBox1.Text +=

    "MailItem = " + item.Actions[1].Name.ToString() + Environment.NewLine;

    textBox1.Text +=

    "MailItem = " + item.Actions[2].Name.ToString() + Environment.NewLine;

    textBox1.Text +=

    "MailItem = " + item.Actions[3].Name.ToString() + Environment.NewLine;

    textBox1.Text +=

    "MailItem = " + item.Actions[4].Name.ToString() + Environment.NewLine;

    }

    }

    }
    this always produces Reply, Reply to All, Foward,Reply to Folder even when you select a new mailitem. It seems that this function is fired everytime you change a selection not just when you select the context menu. So something is wrong here.

    Thursday, August 13, 2009 8:59 PM
  • I think if you want to catch an event when a mail is moved into junk mail folder (correct if i misunderstood)

    then , why can't you use Item add event of junk mail folder ???
    • Proposed as answer by jaz.jazEditor Tuesday, August 18, 2009 9:24 AM
    • Marked as answer by jaz.jazEditor Thursday, August 20, 2009 10:24 AM
    Friday, August 14, 2009 6:18 AM
    Answerer