Get all contacts from exchange server

这一生的挚爱 提交于 2019-11-28 09:57:27

问题


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

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.


回答1:


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.

The code:

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.


来源:https://stackoverflow.com/questions/28057759/get-all-contacts-from-exchange-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!