将新记录添加到私人 Outlook 通讯组列表

发布于 2024-07-10 16:08:29 字数 1051 浏览 5 评论 0原文

我需要从文件或数据库中读取包含姓名和电子邮件的记录,并将它们添加到现有的 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();
    }

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

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信愁 2024-07-17 16:08:29

事实证明这很容易。 我只是错过了对 Resolve 的调用,因为我认为只有在针对 GAL 进行解析时才会这样:

Outlook.Recipient rcp = app.Session.CreateRecipient("Smith, John<[email protected]>");
rcp.Resolve();
list.AddMember(rcp);
list.Save();

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

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

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<[email protected]>");
rcp.Resolve();
list.AddMember(rcp);
list.Save();

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

// 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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文