简体   繁体   中英

Outlook 2010 Add-in - How to determine which MailItem is being shown in the “Reading Pane”

I am trying to write an Add-in for Outlook 2010 that will move emails from my inbox to various archive folders (based on a set of filtering criteria.

My main goal is for all of my new emails to arrive in my inbox and only be moved once they are marked as read and no longer being displayed in the "Reading Pane".

Is there an event handler for when a new mail item is displayed in the "Reading Pane"?

Could one of these interfaces help:

Microsoft.Office.Interop.Outlook.Items
Microsoft.Office.Interop.Outlook.Explorers
Microsoft.Office.Interop.Outlook.Inspectors
Outlook.NavigationPane

您可以使用Explorer.SelectionChange事件来查看何时选择了特定消息(并且取消选择了旧消息)。

I used the Explorer.SelectionChange event and it did the trick. Here is the code to print the email subject when a new item is selected.

    Outlook.Explorer explorer;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        explorer = Application.ActiveExplorer();

        explorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
    }

    void explorer_SelectionChange()
    {
        if(0 == Application.ActiveExplorer().Selection.Count)
        {
            // On start up there are no selections so do nothing...
            return;
        }

        // Get the first mail item
        var item = Application.ActiveExplorer().Selection[1];

        //
        if (item is Outlook.MailItem)
        {
            MessageBox.Show("Selected email's subject: " + ((Outlook.MailItem)item).Subject);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM