【问题标题】:Outlook: How to safely loop through all stores and and set ItemAdd event to all default folders for sent mail?Outlook:如何安全地遍历所有商店并将 ItemAdd 事件设置到所有默认文件夹以发送邮件?
【发布时间】:2019-11-28 08:01:31
【问题描述】:

如果您在 Outlook 中有更多帐户/商店并希望触发 ItemAdd 事件,例如对于所有已发送的项目文件夹。

这是我目前所拥有的,但该事件并未针对所有已发送的项目文件夹触发:

foreach (Outlook.Store store in _outlookNameSpace.Stores)
{
    // _SentItems = null;
    // _items = null;

    try
    {
        _SentItems = store.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);

        _items = _SentItems.Items;
        _items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd); // BUGBUG: The problem is probably here, as the object needs to be alive which is firing the event?
    }
    catch
    {
        AppUtils.DoLog("Skipping this store.");
    }

}

这些家伙被定义为全局类变量:

Outlook.NameSpace _outlookNameSpace;
Outlook.MAPIFolder _SentItems;
Outlook.Items _items;

【问题讨论】:

    标签: c# outlook vsto


    【解决方案1】:

    创建一个包装类,将Items 对象作为其构造函数中的参数,将其保存在一个字段中,并设置一个ItemAdd 事件处理程序。然后,您可以为每个商店初始化一个包装器,然后将其存储在一个列表中,以确保包装器(及其 Items 对象)保持活动状态并可以引发事件。

    【讨论】:

    • 一如既往地非常感谢德米特里。任何可以帮助我的代码示例?
    • 我没有现成的示例,但实现起来很简单。
    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多