【发布时间】:2019-01-22 14:23:46
【问题描述】:
我计划在每次收到所选 Outlook 电子邮件时检索所选电子邮件的邮件项,但事件句柄仅在启动时触发,有时会正确触发。我似乎找不到导致问题的原因,大多数论坛都会导致死胡同,因此这篇文章。
无论如何,这是我的启动方法的sn-p:
private void Main_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
Outlook.Explorer currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
outlookNameSpace = this.Application.GetNamespace("MAPI");
inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
items = inbox.Items;
items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
}
这是我的 CurrentExplorer_Event 方法的 sn-p:
private void CurrentExplorer_Event()
{
newSelectedEmail = new Email();
Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder;
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
GetEmailInfoFromOutlookEmail(mailItem);
}
}
}
catch (Exception ex)
{
Operations.SaveLogToFile(LogType.Error, "Main - CurrentExplorer_Event", ex.Message, ex.StackTrace);
}
}
非常感谢任何帮助。谢谢!
【问题讨论】:
标签: c# vsto outlook-addin