简体   繁体   English

Outlook 2010加载项-如何确定“阅读窗格”中显示的是哪个MailItem

[英]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. 我正在尝试编写Outlook 2010加载项,该加载项会将电子邮件从收件箱移动到各种存档文件夹(基于一组过滤条件)。

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. 我使用了Explorer.SelectionChange事件,它成功了。 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);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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