在Outlook VSTO C#中捕获“单击答复/答复全部”事件

问题描述 投票:1回答:2

当前,我正在使用C#语言为VSTO Outlook创建加载项。

我从Microsoft's Walkthrough: Create your first VSTO Add-in for Outlook学到了一些基础知识,其中我学会了在用户撰写新邮件时向邮件正文中添加一些文本。

我想对回复和回复所有事件都执行相同的操作(向邮件正文中添加文本)。

我搜索了Outlook对象模型,但没有发现有用的东西。有人可以帮我吗?

c# outlook vsto outlook-addin visual-studio-2019
2个回答
0
投票

使用Explorer.SelectionChange事件在所选项目上设置事件接收器(Explorer对象可以来自Application.ActiveExplorer属性,然后跟踪MailItem.Reply / ReplyAll事件。

如果您不关心旧项目,则只需使用Inspectors.NewInspector事件。


0
投票

感谢您的回复。我尝试使用上面的Explorer.SelectionChange事件,并写成这样:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;

namespace TestOutlookAddIn1
{
    public partial class ThisAddIn
    {
        Outlook.Explorer explorer;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            explorer = Application.Explorers[1];
            explorer.SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Note: Outlook no longer raises this event. If you have code that 
            //    must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
        }

        void explorer_SelectionChange()
        {
            MessageBox.Show("SELECTION CHANGED");

            var selection = this.Application.ActiveExplorer().Selection;
            if (selection != null && selection.Count == 1 && selection[1] is Outlook.MailItem)
            {
                Outlook.MailItem selectedMail = selection[1] as Outlook.MailItem;

                MessageBox.Show("Conditions passed.");
                MessageBox.Show("ReplyRecipientNames : " + selectedMail.ReplyRecipientNames);

            }
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

现在,我既可以捕获答复又可以成功答复所有事件。

但是我不知道如何只指定答复和使用MailItem.Reply / ReplyAll事件全部答复

此外,explorer_SelectionChange()方法执行两次,并且ReplyRecipientNames结果始终不正确]。请帮助。

© www.soinside.com 2019 - 2024. All rights reserved.