【问题标题】:Custom VSTO Context Menu - Active Inspector自定义 VSTO 上下文菜单 - 活动检查器
【发布时间】:2019-09-13 07:45:26
【问题描述】:

我正在尝试在 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();

        }

当我右键单击并选择上下文菜单项时,我收到“对象引用未设置为对象的实例”错误。

功能区项目正常工作。

【问题讨论】:

    标签: c# outlook vsto outlook-addin


    【解决方案1】:

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

    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();
                        }
                    }
                }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 2015-05-20
      • 1970-01-01
      相关资源
      最近更新 更多