用于替换电子邮件中文本的 Outlook 插件

Outlook plugin to replace text in emails

Visual Studio2015.展望2016.

我想编写一个插件,在阅读窗格或检查器中查看电子邮件时用超链接替换某些形式的文本。

我可以订阅 ItemLoad 事件:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.ItemLoad += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemLoadEventHandler(OnItemLoad);
    }

    private void OnItemLoad(object item)
    {
        Outlook.MailItem mailItem = item as Outlook.MailItem;

        if (mailItem != null)
        {
            System.Diagnostics.Debug.WriteLine("OnItemLoad: " + mailItem.Subject);
        }
    }

但是当它由于某种原因被触发时,我无法访问 Outlook.MailItem 实例上的任何内容。我收到以下异常:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in FirstOutlookAddIn.dll but was not handled in user code

Additional information: The item’s properties and methods cannot be used inside this event procedure.

提前致谢!

该错误消息非常明确 - 在某些事件处理程序中无法访问 OOM 属性或方法。

一种解决方法是等到您退出事件处理程序 - 使用不同的事件(如果可用),或在 OOM 事件处理程序中启用计时器,然后在计时器事件处理程序中执行您需要的操作做(当它触发时你将离开 OOM 事件处理程序)。使用 Forms 命名空间中的计时器 class,因为它在主线程上触发。

但请记住,修改现有项目不是一个好主意 - 更改可能会持续存在(同时更新上次修改日期)或者 Outlook 会提示用户保存更改。

尝试使用通过 Inspector.GetWordEditor 公开的 Word 编辑器。对于阅读窗格,您可以使用 ReadingPane object in Redemption(我是它的作者)。