如何在 VSTO 中打开之前更改 Outlook 电子邮件项目

How to change Outlook email item before it openned in VSTO

我尝试用邮件传递一些服务信息。在发送之前将其添加到电子邮件正文中。在 Outlook 中打开电子邮件时,有没有办法从 MailItem.HtmlBody 中提取和删除此信息。

如果您想在项目到达用户邮箱后立即删除信息,您可以处理 NewMailEx event of the Application class which is fired when a new item is received in the Inbox. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID 方法并处理项目。

可以在检查器和资源管理器中查看 Outlook 项目windows。

对于资源管理器,您可以处理资源管理器 class 的 SelectionChange 事件,当用户以编程方式或通过与用户界面交互选择不同或附加的 Microsoft Outlook 项目时,该事件将被触发。当用户(以编程方式或通过用户界面)单击或切换到包含项目的不同文件夹时,也会发生此事件,因为 Outlook 会自动选择该文件夹中的第一个项目。

对于检查器,您可以处理检查器 class 的 NewInspector 事件,只要打开新的检查器 window,它就会被触发,无论是作为用户操作的结果还是通过程序代码。该事件发生在新的 Inspector 对象创建之后但检查器 window 出现之前。因此,我建议等待第一个 Activate 事件来访问打开的 MailItem 实例。