从 EWS 托管 API 检索联系人

发布于 2024-12-04 18:20:13 字数 79 浏览 2 评论 0原文

我研究了执行此操作的方法并查看了 API 文档,但没有成功。有谁知道我检索特定用户的联系人所需的代码是什么。

任何帮助将不胜感激

I've researched ways to do this and looking into the API documentation with no luck. Does anyone know what is the necessary code for me to retrieve the contacts for a specific user.

Any help will be greatly appreciated

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

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

发布评论

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

评论(2

夏の忆 2024-12-11 18:20:13

我在网上找到的所有其他答案都过于复杂。 ResolveName 应该可以工作。

以下示例代码对我有用;剩下的就是查阅不同的词典并获取必要的信息。

    public void findContact(string name)
    {
        NameResolutionCollection coll = service.ResolveName(name,
            ResolveNameSearchLocation.ContactsThenDirectory,
            true);
        foreach (NameResolution res in coll)
        {
            Contact contact = res.Contact;
            if (contact != null)
            {
                // retrieve contact info here
                if (contact.PhoneNumbers != null)
                {
                    Console.WriteLine("get different kinds of phone numbers from here");
                }

                if (contact.EmailAddresses != null)
                {
                    Console.WriteLine("get different kinds of email addresses from here");
                }

                return;
            }
        }
    }

All the other answers I found online are overly complicated. ResolveName should work.

The following example code worked for me; the rest is just looking into the different dictionaries and getting the necessary info out.

    public void findContact(string name)
    {
        NameResolutionCollection coll = service.ResolveName(name,
            ResolveNameSearchLocation.ContactsThenDirectory,
            true);
        foreach (NameResolution res in coll)
        {
            Contact contact = res.Contact;
            if (contact != null)
            {
                // retrieve contact info here
                if (contact.PhoneNumbers != null)
                {
                    Console.WriteLine("get different kinds of phone numbers from here");
                }

                if (contact.EmailAddresses != null)
                {
                    Console.WriteLine("get different kinds of email addresses from here");
                }

                return;
            }
        }
    }
凶凌 2024-12-11 18:20:13

基本上,它可以归结为以下三行:

var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
    {Credentials = new NetworkCredential("username", "password")};

service.AutodiscoverUrl("targetmailaddress", url => true);

var items = service.FindItems(new FolderId(WellKnownFolderName.Contacts, new Mailbox("targetmailaddress")), new ItemView(512));

您需要将 targetmailaddress 替换为您要查找的地址。如果您只有一个 Exchange Server,则可以省略自动发现部分,并将服务 URL 添加到第一个列表中的服务初始化中。

像往常一样,您可以将项目过滤器添加到 FindItems 调用中。

Basically, it boils down to these three lines:

var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
    {Credentials = new NetworkCredential("username", "password")};

service.AutodiscoverUrl("targetmailaddress", url => true);

var items = service.FindItems(new FolderId(WellKnownFolderName.Contacts, new Mailbox("targetmailaddress")), new ItemView(512));

You need to replace targetmailaddress with the address you are looking for. If you only have one Exchange Server, you can omit the AutoDiscover part and add the service URL to the service initialization in the first list.

As usual, you can add an item filter to the FindItems call.

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