将新记录添加到私人Outlook通讯组列表 [英] Add new records to private Outlook distribution list

查看:106
本文介绍了将新记录添加到私人Outlook通讯组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to read records containing name and email from a file or database and add them to an existing Oulook distribution list (from the private contacts, not from the GAL).

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

I just saw examples of reading from OL using LINQ to DASL which I have working for mail and appointments, but I can't figure out how to list the contents of a dist list:

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();
    }

一旦我可以阅读成员,我就需要能够添加新成员,这将是更多技巧.任何帮助将不胜感激.

Once I can read the members I need to be able to add new ones which is even more trick. Any help would be appreciated.

推荐答案

事实证明这很容易.我只是错过了Resolve的电话,因为我以为只有在您针对GAL进行解决时,

Turns out it is easy enough. I was simply missing the call to Resolve as I thought that was only if you were resolving against the GAL:

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

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

And I can create an iterator that uses the distList.GetMember method:

//将DistListItem.GetMembers()包装为迭代器

// Wrap DistListItem.GetMembers() as an iterator

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);
        }
    }
}

这篇关于将新记录添加到私人Outlook通讯组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆