如何使用 ews-javascript-api 从目录文件夹中获取联系人?

How to get contacts from Directory folder using ews-javascript-api?

大家好,

我可以成功地从您的联系人文件夹中获取所有联系人。

如何从 EWS 获取该目录文件夹中的所有联系人?

我试过这段代码,但它抛出错误:

Exception: The distinguished folder name is unrecognized.

ews.EwsLogging.DebugLogEnabled = false;
let exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);

exch.Credentials = new ews.ExchangeCredentials("username", "password");

exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");

exch.FindItems(
    [
        new ews.FolderId(ews.WellKnownFolderName.Directory) // Changed .Contacts to .Directory
    ],
    null,
    null,
    new ews.ItemView(10),
    null,
    ews.ServiceErrorHandling.ReturnErrors
).then(function (resp) {
    resp.Responses[0].Results.Items.forEach(function (item) {
        console.log(item.EmailAddresses.Entries.Values);
    });
}, function (ei) {
    console.log(ei.stack, ei.stack.split("\n"));
});

您想在 ExchangeService 实例上使用 ResolveName 方法,而不是使用文件夹类型。目录信息来自 Exchange 中的全局地址列表 从 Active Directory 填充

参考- https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservice.resolvename(v=exchg.80).aspx

https://msdn.microsoft.com/en-us/library/office/jj190895(v=exchg.150).aspx