即使在 Outlook 中,如何附加到 BeforeAttachmentRead?

How to Attach to the BeforeAttachmentRead even in Outlook?

我想在用户查看 Outlook 中的附件之前采取一些措施,并想挂接到 VSTO 插件中的 BeforeAttachmentRead 事件。我见过遍历收件箱并将事件添加到每个 MailItem:

的代码
foreach (object o in inbox.Items)
{
 mailItem = o as Outlook.MailItem;
 ...
 ((Outlook.ItemEvents_10_Event)mailItem).BeforeAttachmentRead += new Outlook.ItemEvents_10_BeforeAttachmentReadEventHandler(MailItem_BeforeAttachmentRead);
}

但这对我来说似乎效率很低(收件箱中的子文件夹呢?)

是否有更有效的方法来响应 BeforeAttachmentRead 事件?

But this seems very inefficient to me (and what about subfolders in the inbox?)

我同意。

我建议 you subscribe to the selection change event of the Outlook Explorer. Now everytime the user selects something you can check if it is a mailitem (it can be other things) and then subscribe to the BeforeAttachmentRead event. You could actually check for MailItem Attachments count first.。如果邮件没有附件,那你就没事了。

还有一些其他的事情要检查;

  1. 检查资源管理器 CurrentFolder.WebViewOn 是否为假;
  2. 检查select离子计数 - 如果它是 1
  3. ,您只想做某事
  4. 一个用户可以select很多不同的东西。在施放 selection 之前检查它实际上是 Outlook.MailItem
  5. 类型