如何从Exchange Server获取联系人列表? [英] How to get contact list from Exchange Server?

查看:333
本文介绍了如何从Exchange Server获取联系人列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我从Exchange Server获取联系人列表的最简单方法吗?我正在使用C#

Can anyone tell me the simplest way to get a contact list from Exchange Server? I'm using C#

从我发现的情况来看, Exchange Web服务仅适用于Exchange Server 2007及更高版本。那将是我的第一选择,但我也希望替代Exchange的早期版本(WebDav或其他版本)。目录服务不是一种选择。

From what I found out, Exchange Web Services only exists for Exchange Server 2007 and beyond. That would be my first option, but I'd also like an alternative for previous versions of Exchange (WebDav or something). Directory Services is not an option.

推荐答案

这是从EWS交换来从联系人列表中获取联系人列表的方法。我不确定如何从全局列表中获取联系人,只是一个小时前才查看过API。

This is how to get the contact list from your contacts list in exchange using EWS. I'm not sure how to get contacts from the global list yet, only looked at the API an hour ago.

private static void ListContacts(ExchangeService svc) {
    foreach (var v in svc.FindItems(WellKnownFolderName.Contacts,
                                    new ItemView(20))) {
        Contact contact = v as Contact;
        ContactGroup contactGroup = v as ContactGroup;

        //v.Load(); // Turns out you don't need to load for basic props.
        if (contact != null) {
            Console.WriteLine("Contact: {0} <{1}>",
                contact.DisplayName,
                contact.EmailAddresses[EmailAddressKey.EmailAddress1]);
        } else if (contactGroup != null) {
            Console.WriteLine("Contact Group: {0}", contactGroup.DisplayName);
            switch (svc.RequestedServerVersion) {
                case ExchangeVersion.Exchange2007_SP1:
                    ExpandGroupResults groupResults
                        = svc.ExpandGroup((contactGroup.Id));
                    foreach (var member in groupResults) {
                        Console.WriteLine("+ {0} <{1}>",
                            member.Name, member.Address);
                    }
                    break;
                case ExchangeVersion.Exchange2010:
                    foreach (GroupMember member in contactGroup.Members) {
                        Console.WriteLine("+ {0} <{1}>",
                        member.AddressInformation.Name,
                        member.AddressInformation.Address);
                    }
                    break;
                default:
                    Console.WriteLine(
                        "** Unknown Server Version: {0}",
                        svc.RequestedServerVersion);
                    break;
            }
        } else {
            Console.WriteLine("Unknown contact type: {0} - {1}",
                contact.GetType(), v.Subject);
        }
    }
}

我省略了创建服务,请查看 Exchange Web服务API 了解更多信息。

I've ommited creating the service for verbocity, have a look at the Exchange Web Services API for more information.

这篇关于如何从Exchange Server获取联系人列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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