C# Outlook 2007捕获ReplyToAll事件的共享加载项
我使用的是VS2010和DotNetFramework2.0。 我已经在Extensibility->Shared Add-ins for Outlook中创建了一个项目。 我正在尝试捕获ReplyToll事件,但它没有被触发。 请查看以下代码: 连接方法C# Outlook 2007捕获ReplyToAll事件的共享加载项,c#,.net,outlook,add-in,outlook-addin,C#,.net,Outlook,Add In,Outlook Addin,我使用的是VS2010和DotNetFramework2.0。 我已经在Extensibility->Shared Add-ins for Outlook中创建了一个项目。 我正在尝试捕获ReplyToll事件,但它没有被触发。 请查看以下代码: 连接方法 inspectors = applicationObject.Inspectors; inspectors.NewInspector += new Outlook.InspectorsEvent
inspectors = applicationObject.Inspectors;
inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
void inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
mailItem = null;
try
{
Outlook.NameSpace ns = Inspector.Session;
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderInbox);
foreach (object o in inbox.Items)
{
mailItem = o as Outlook.MailItem;
if (mailItem != null)
{
break;
}
}
if (mailItem == null)
{
MessageBox.Show("Couldn't find a mail item.");
}
else
{
((Outlook.ItemEvents_10_Event)mailItem).ReplyAll += new
Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
}
}
catch (Exception ex)
{
MessageBox.Show("asdgh"+ex.StackTrace);
}
}
void Connect_ReplyAll(object Response, ref bool Cancel)
{
MessageBox.Show(Response+"Hello You have Clikced ReplyTOAll");
}
但是调用了Connect\u replyll方法
怎么了
正在工作但已注册事件的新代码
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
applicationObject = (Outlook.Application)application;
if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
addInInstance = addInInst;
inspectors = applicationObject.Inspectors;
explorer = applicationObject.Explorers.Application.ActiveExplorer();
explorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
inspectors.NewInspector += new
Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
}
catch(Exception ex)
{
MessageBox.Show(""+ex.StackTrace);
}
//((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)mailItem).Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(ReplyToAllEvent);
}
void explorer_SelectionChange()
{
try
{
Outlook.MailItem mailExplorer=null;
mailTO = "";
mailCC = "";
mailBCC = "";
foreach (object selectedItem in explorer.Selection)
{
mailExplorer = selectedItem as Outlook.MailItem;
//MessageBox.Show("" + mailItem.EntryID.ToString());
break;
}
if (mailExplorer != null)
{
if (selectedItems.Contains(mailExplorer.EntryID.ToString()))
{
selectedItems.Remove(mailExplorer.EntryID);
((Outlook.ItemEvents_10_Event)mailExplorer).ReplyAll -= new Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
((Outlook.ItemEvents_10_Event)mailExplorer).Reply -= new Outlook.ItemEvents_10_ReplyEventHandler(Connect_Reply);
}
((Outlook.ItemEvents_10_Event)mailExplorer).ReplyAll +=
new Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
((Outlook.ItemEvents_10_Event)mailExplorer).Reply +=
new Outlook.ItemEvents_10_ReplyEventHandler(Connect_Reply);
selectedItems.Add(mailExplorer.EntryID);
mailTO = mailExplorer.To;
mailCC = mailExplorer.CC;
mailBCC = mailExplorer.BCC;
}
}
catch(Exception ex)
{
MessageBox.Show(""+ex.StackTrace);
}
}
“一旦我用ReplyAll事件注册了mailitem,如果选择了相同的mailitem,那么该事件将触发多次。”使用上述代码可以解决此问题,但在分离该事件时,我收到了新的错误
请帮帮我
我收到此错误,您希望引发事件的COM对象需要处于活动状态。上面的代码循环遍历收件箱中的所有项目(哎哟!为什么?),并在每次迭代中使用相同的变量,从而删除以前的值。
要回复邮件,首先需要选择它,因此您只需循环浏览所选项目(Explorer.Selection集合)。通过挂接Explorer.SelectionChanged事件跟踪选择,在该事件处理程序中,循环浏览Explorer.selection collation中的所有项目,并将它们放入您自己的
列表中。这样,对象将一直处于活动状态,直到您从列表中删除它们。
比这更好的是,不要使用List
List,而是创建自己的包装器,将MailItem存储为私有成员,并在该包装器中连接ReplyAll事件。这样,当事件激发时,您将知道哪个MailItem对象引发了事件。然后,可以将每个选定邮件项的包装器存储在列表
集合中。您可以给我演示如何捕获Outlook事件(如Reply)的示例吗所有帮助都将得到感谢我没有准备好运行的示例代码段。您到底遇到了什么问题?我只想捕获REplyToAll事件并覆盖此事件,以检查mailitem是否有多个收件人,或提示您是此邮件的密件抄送人。etcI了解这一点,但这将不仅仅是几行代码-请参阅我的回复。@C_J-查看。不能使用入口ID的列表
——必须使用包装器或列表
来正确管理事件。