从交换服务器获取所有联系人 [英] Get all contacts from exchange server
问题描述
我想从Exchange服务器获取所有用户,我不想获取用户的联系人.实际上,我想让所有AD用户都成为我们无法连接的Active Directory.
I want to get all users from Exchange server, I don't want to get user's contacts. In fact, I want to get all AD users as Active Directory which we can't connect to.
mExchangeService.ImpersonatedUserId = new ImpersonatedUserId
{
Id = "jack@aa.com",
IdType = ConnectingIdType.SmtpAddress
};
var contacts = _mExchangeService.FindItems(new FolderId(WellKnownFolderName.Contacts),new ItemView(1000));
我可以通过上面的代码来获取用户的联系,但这不是我想要的,我想使用服务帐户来获取所有Exchange Web服务用户.
I can above code to get user's contact, but that's not I want, I want use a service account to get all Exchange web service users.
推荐答案
You can sort of use EWS for retrieving your directory users using ExhangeService.ResolveName
. The problem is that EWS will return no more than 100 users and there is no way to change it or to do any paging. So if you are in a larger company you can't really do it using EWS.
代码:
var nameResolutionCollection = service.ResolveName("SMTP:",
ResolveNameSearchLocation.DirectoryOnly, true);
foreach (var c in nameResolutionCollection)
{
Console.WriteLine(c.Mailbox.Address);
}
Console.WriteLine(nameResolutionCollection.Count()); // Maximum 100 users.
这篇关于从交换服务器获取所有联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!