当前,我正在使用C#语言为VSTO Outlook创建加载项。
我从Microsoft's Walkthrough: Create your first VSTO Add-in for Outlook学到了一些基础知识,其中我学会了在用户撰写新邮件时向邮件正文中添加一些文本。
我想对回复和回复所有事件都执行相同的操作(向邮件正文中添加文本)。
我搜索了Outlook对象模型,但没有发现有用的东西。有人可以帮我吗?
使用Explorer.SelectionChange
事件在所选项目上设置事件接收器(Explorer
对象可以来自Application.ActiveExplorer
属性,然后跟踪MailItem.Reply
/ ReplyAll
事件。
如果您不关心旧项目,则只需使用Inspectors.NewInspector
事件。
感谢您的回复。我尝试使用上面的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结果始终不正确]。请帮助。