0

我正在为 Outlook 开发一些 COM 插件扩展,我想在将项目放入特定文件夹或其子文件夹时触发事件。我正在使用 Items_ItemAdd 方法作为 drop 事件侦听器。如果将项目放入“父”文件夹,它工作正常,但当项目放入子文件夹时没有任何反应。

这是我正在使用的代码:

private void ThisAddIn_Startup(object sender, System.EventArgs e
{
    foreach (Outlook.Folder folder in foldersPaths)
    {
       costumUserFolder = folder.Items;
       costumUserFolder.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    }
}

folderPaths 是 Outlook.Folder 的列表,包含我要收听事件的文件夹及其所有子文件夹。

我在Items_ItemAdd方法中监听这个事件。

有任何想法吗?

4

2 回答 2

2

您需要在每个文件夹的 Items 集合上安装事件接收器。

为了确保在您的应用程序运行时所有 Items 对象都处于活动状态,请将 Items 存储在列表中(例如List<Outlook.Items>

于 2013-07-29T13:52:20.623 回答
0
    //Please find the implemented tested working Solution:


    Outlook.Items oMailItems = null; //Globally declared object
    List<Outlook.Items> allInboxFolder = new List<Outlook.Items>(); //Globally declared
Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    //Implemented Threading for each item recieved to Inbox Folder
    //Outlook.Items oMailItems = null; //Globally declared object
    oMailItems = inbox.Items;
    oMailItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ThreadStarter);
    allInboxFolder.Add(oMailItems); //make all subfolders events live
    foreach (Outlook.Folder folder in inbox.Folders)
    {
        oMailItems = folder.Items;
        oMailItems.ItemAdd += new   Outlook.ItemsEvents_ItemAddEventHandler(ThreadStarter);
        allInboxFolder.Add(oMailItems);
    }

    private void ThreadStarter(Object Item)
    {
        //InboxFolderItemAdded invoked by thread
        System.Threading.Thread IncomingMailThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(this.InboxFolderItemAdded));
        IncomingMailThread.IsBackground = true;
        IncomingMailThread.Start(Item);
    }
于 2019-02-08T07:54:19.760 回答