0

Visual Studio (C#) 中的 Outlook 2010 插件。

我试图找到一种方法来区分从资源管理器中检索到的 .AttachmentSelection (仅在收件箱上预览邮件项时)和从检查器中检索到的 .AttachmentSelection 之间的区别(当双击并实际在单独的窗口中打开邮件时) , 在 Outlook 中右键单击附件本身时

我正在尝试做类似的事情:

public void ButtonClick(Office.IRibbonControl control)
{
    //right clicked attachment item -> context menu
    if (control.Context is Outlook.AttachmentSelection)
    {
        if (control.Context is Outlook.Inspector)
            MessageBox.Show("inspector");
        else if (control.Context is Outlook.Explorer)
            MessageBox.Show("explorer");
     }
}

但是一旦第一个'if'有效,内部的都失败了。因为上下文不是 Outlook Inspector,也不是 Outlook Explorer。Microsoft 示例和解释不是很有帮助,因为在他们的代码片段中,他们只是将附件消息框起来,而没有深入验证它们的来源(explorer\inspector)。

我需要获取 Mailitem,用户可以从中右键单击附件,然后从中提取信息,而不是直接使用附件。

任何的想法 ?任何人 ?

4

2 回答 2

1

您可以使用 Application 类的ActiveWindow方法来确定附件是从 Explorer 窗口还是 Inspector 窗口打开的。该方法返回一个表示桌面上当前 Microsoft Outlook 窗口的对象,可以是 Explorer 对象,也可以是 Inspector 对象。如果没有打开 Outlook 资源管理器或检查器,则返回 Nothing。

此外,您可能会发现 Outlook 项目的BeforeAttachmentPreview事件很有帮助。在预览与父对象实例关联的附件之前触发它。即,在预览附件之前触发事件,从活动浏览器的阅读窗格中的附件条或从活动检查器。请注意,您可以取消操作。您只需要将取消参数设置为 true。

于 2015-02-06T14:10:21.147 回答
0

怎么样?直接来自msdn

Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
      {
          if (mailItem.EntryID == null)
          {
              mailItem.Subject = "This text was added by using code";
              mailItem.Body = "This text was added by using code";
          }

    }
于 2015-02-06T14:03:04.603 回答