将新记录添加到私有Outlook分发列表

我需要从文件或数据库中读取包含名称和电子邮件的记录,并将它们添加到现有的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();
    }
一旦我能够阅读成员,我需要能够添加新的成员,这是更多的技巧。任何帮助,将不胜感激。     
已邀请:
事实证明这很容易。我只是错过了对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);
        }
    }
}
    

要回复问题请先登录注册