自定义 VSTO 上下文菜单 - 活动检查器

Custom VSTO Context Menu - Active Inspector

我正在尝试在 Outlook 中添加一个上下文菜单项目,该项目将自定义回复邮件、发送和删除原始项目。

<contextMenus>
    <contextMenu idMso="ContextMenuMailItem">
      <menu id="OutlookPushContextMenu" label="EBS Plugins" getImage="imageLogo_GetImage" insertBeforeMso="Copy">
        <button id="OutlookPushEmail" label="Autograph Request" getImage="imageEmail_GetImage" onAction="AutographRequest_Click"/>
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuMultipleItems">
      <menu id="OutlookPushContextMenu2" label="EBS Plugins" getImage="imageLogo_GetImage" insertBeforeMso="Copy">
        <button id="OutlookPushEmail2" label="Autograph Request" getImage="imageEmail_GetImage" onAction="AutographRequest_Click"/>
      </menu>
    </contextMenu>
  </contextMenus>
      public void AutographRequest_Click(Office.IRibbonControl control)
        {
            Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
            Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
            Outlook.MailItem response = mailItem.ReplyAll();

            response.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
            response.HTMLBody = "<p>Text</p> " + response.HTMLBody;
            response.Send();
            mailItem.Delete();

        }

当我右键单击并 select 上下文菜单项时,出现 "Object reference not set to an instance of an object" 错误。

功能区项目没有问题。

你假设总是有一个活跃的检查员。你确定是这样吗? 我想你的意思是在资源管理器中处理当前选定的消息:

public void AutographRequest_Click(Office.IRibbonControl control)
        {
            Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
            if (explorer != null)
            {
                Outlook.Selection selection = explorer.Selection;
                if (selection.Count >= 1)
                {  
                    Outlook.MailItem mailItem = selection[1] as Outlook.MailItem;
                    if (mailItem != null) //could be something other than MailItem
                    {
                        Outlook.MailItem response = mailItem.ReplyAll();

                        response.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
                        response.HTMLBody = "<p>Text</p> " + response.HTMLBody;
                        response.Send();
                        mailItem.Delete();
                    }
                }
            }

    }