【问题标题】:Add new records to private Outlook distribution list将新记录添加到私人 Outlook 通讯组列表
【发布时间】:2010-05-06 01:57:29
【问题描述】:

我需要从文件或数据库中读取包含姓名和电子邮件的记录,并将它们添加到现有的 Oulook 分发列表(来自私人联系人,而不是来自 GAL)。

我刚刚看到了使用 LINQ to DASL 从 OL 读取的示例,这些示例用于处理邮件和约会,但我不知道如何列出 dist 列表的内容:

private static void GetContacts()
    {
         Outlook.Application app = new Outlook.Application();
         Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
 var distLists = from item in folder.Items.AsQueryable<MyDistList>()
                 where item.DLName == "My Dist List"
                 select item.Item;

        var builder = new StringBuilder();

        foreach (var list in distLists)
        {
            builder.AppendLine(list.DLName);
            foreach (var item in list.Members)
            {
            // can't figure out how to iterate through the members here
            // compiler says Object doesn't have GeNumerator...
            }
        }

        Console.WriteLine(builder.ToString());
        Console.ReadLine();
    }

一旦我可以阅读成员,我就可以添加新成员,这更加诡计。任何帮助将不胜感激。

【问题讨论】:

    标签: outlook distribution-list


    【解决方案1】:

    事实证明这很容易。我只是错过了对 Resolve 的调用,因为我认为这只是在您解决 GAL 时:

    Outlook.Recipient rcp = app.Session.CreateRecipient("Smith, John<j.smith@test.com>");
    rcp.Resolve();
    list.AddMember(rcp);
    list.Save();
    

    我可以创建一个使用 distList.GetMember 方法的迭代器:

    // 将 DistListItem.GetMembers() 包装成一个迭代器

    public static class DistListItemExtensions
    {
        public static IEnumerable<Outlook.Recipient> Recipients(this Outlook.DistListItem distributionList)
        {
            for (int i = 1; i <= distributionList.MemberCount; i++)
            {
                yield return distributionList.GetMember(i);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多