首页 > 解决方案 > 防止 MailItem.Reply 在 Outlook 2016 中打开检查器窗口

问题描述

当用户单击“回复”按钮时,我正在为 Outlook 构建一个插件以在 Outlook 电子邮件中添加自定义签名。一旦用户点击资源管理器中的回复按钮,一个新的检查器就会打开,我用代码(s#cks)关闭检查器。可能有一种方法可以完全禁用回复检查器的打开。

    private Microsoft.Office.Tools.CustomTaskPane CustomTaskPane;
    UserDetail usr = null;
    Outlook.Explorer currentExplorer = null;
    Outlook.MailItem mailItem;
    private Inspector replyInspector;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        currentExplorer = this.Application.ActiveExplorer();
        currentExplorer.SelectionChange +=
                            new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
    }
    private void CurrentExplorer_Event()
    {
        if (this.Application.ActiveExplorer().Selection.Count == 1
        && this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
        {
            if (mailItem != null)
            {
                // when the reply button is clicked
                ((Outlook.ItemEvents_10_Event)mailItem).Reply -= new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);

                // When an item is selected
                Outlook.Selection mySelection = this.Application.ActiveExplorer().Selection;
                Outlook.MailItem mailitem = null;
                foreach (Object obj in mySelection)
                {
                    if (obj is Outlook.MailItem)
                    {
                        mailitem = (Outlook.MailItem)obj;
                        if (mailitem != null)
                        {
                            if (mailitem.Sent)
                            {

                            else
                            {
                                // Compose
                            }
                        }
                    }
                }
            }
            mailItem = this.Application.ActiveExplorer().Selection[1];
            ((Outlook.ItemEvents_10_Event)mailItem).Reply += new
             Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
            // Close Inspector
            replyInspector.Close(OlInspectorClose.olDiscard);
        }
        else
        {
        }
    }

    void MailItem_Reply(Object response, ref bool cancel)
    {
        try
        {
            MailItem mitem = (Outlook.MailItem)response;
            replyInspector = (mitem).GetInspector;
            replyInspector.Activate();
            (mitem).HTMLBody = tempSignature + ((Outlook.MailItem)response).HTMLBody;
        }
        catch (System.Exception e)
        {
            MessageBox.Show(e.ToString());
        }
    }

标签: c#vstooutlook-addinoffice-addins

解决方案


首先,如果您要打开检查器,为什么还要关闭它?为什么不在检查器打开时插入签名?

其次,您不能连接两个 HTML 字符串并期望生成的字符串是有效的 HTML,这两个需要合并。或者,更好的是,使用 Word 对象模型(Word.Document返回自Inspector.WordEditor)在邮件正文的任何​​位置插入任何文本。


推荐阅读