gpt4 book ai didi

outlook - 共享邮箱 Outlook 2007 的新邮件提醒

转载 作者:行者123 更新时间:2023-12-01 22:26:37 25 4
gpt4 key购买 nike

我正在尝试为 Outlook 2007 中的共享邮箱创建弹出邮件警报。下面的代码不起作用。为什么?

private Microsoft.Office.Interop.Outlook._Explorers Explorers;
private Microsoft.Office.Interop.Outlook.NameSpace outlookNamespace;
private Microsoft.Office.Interop.Outlook.MAPIFolder mFolder;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Explorers = this.Application.Explorers;
outlookNamespace = this.Application.GetNamespace("MAPI");
mFolder = outlookNamespace.Folders["Mailbox -AdditionalMailBox"].Folders["Inbox"];
mFolder.Application.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx );
}
private void Application_NewMailEx(string EntryID)
{
MessageBox.Show("New MailReceived!");
}

最佳答案

为了使您的事件处理程序能够在垃圾回收中幸存 - 您需要通过将包含事件的对象添加为私有(private)成员变量来确保它们保持事件状态。尝试添加 Application 私有(private)类变量,您的事件订阅应该可以正常工作。请参阅related SO post了解更多详情。

private Microsoft.Office.Interop.Outlook.Application application;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
application = this.Application;
Explorers = application.Explorers;
// ...
application.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx );
}

您发现的另一个问题是 NewMailEx 仅针对您的主邮箱触发 - 而不是辅助邮箱,如 confirmed in this forum post 。您将需要依赖 Folder.Items事件ItemAdd .

private Outlook.Items mFolderItems;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// ...
mFolderItems = mFolder.Items; // avoid GC for ItemAdd event
mFolderItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(mFolder_ItemAdd);
// ...
}
private void mFolder_ItemAdd(object addedItem)
{
Outlook.MailItem newItem = addedItem as Outlook.MailItem;
}

关于outlook - 共享邮箱 Outlook 2007 的新邮件提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9683894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com