Outlook 2010 加载项 - 如何确定 "Reading Pane" 中显示的是哪个 MailItem

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

我正在尝试为 Outlook 2010 编写一个加载项,它将电子邮件从我的收件箱移动到各种存档文件夹(基于一组过滤条件。

我的主要目标是让我所有的新邮件都到达我的收件箱,并且只有在它们被标记为已读并且不再显示在 "Reading Pane" 中时才会被移动。

"Reading Pane" 中显示新邮件项目时是否有事件处理程序?

这些接口之一可以帮助:

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

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

我使用了 Explorer.SelectionChange 事件,它成功了。这是选择新项目时打印电子邮件主题的代码。

    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);
        }
    }