我正在使用VSTO创建一个事件,当发送电子邮件时触发。目标是更改附件。
我已经有了其他运行在"ItemSend"事件中的插件,但问题是,我希望我的插件首先运行。据我所知,Outlook插件发送事件没有执行顺序,但即使只按名称或GUID排序,也必须有一些顺序...
我尝试了这个解决方案(问题是,如果我打开2个邮件窗口,第一个窗口就不会运行事件... :( 有些覆盖事件的问题)。
我已经有了其他运行在"ItemSend"事件中的插件,但问题是,我希望我的插件首先运行。据我所知,Outlook插件发送事件没有执行顺序,但即使只按名称或GUID排序,也必须有一些顺序...
我尝试了这个解决方案(问题是,如果我打开2个邮件窗口,第一个窗口就不会运行事件... :( 有些覆盖事件的问题)。
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.Inspectors.NewInspector += new InspectorsEvents_NewInspectorEventHandler(Custom_Inspector);
//This run in the end off all ItemSend Events.... :(
//this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(MyFunction2);
}
private void Custom_Inspector(Inspector Inspector)
{
if (Inspector != null && Inspector.CurrentItem != null && Inspector.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem.EntryID == null)
{
((ItemEvents_10_Event)mailItem).Send += new ItemEvents_10_SendEventHandler(MyFunction);
}
}
}
void MyFunction(ref bool Cancel)
{
MailItem mailItemContext = ((Inspector)this.Application.ActiveWindow()).CurrentItem as MailItem;
if (mailItemContext != null)
{
//my custom code here
}
}