0
votes

I need to get all contacts and distribution lists (with their contacts) from my Outlook using Exchange WebService.

I have Visual 2017, and EWSManaged API 2.2 installed. My server has Exchange 2013, and I have installed Exchange 2013 101 Code Samples.

What I have now:

Option 1. I have that, but only 100 contacts are displayed:

var nameResolutionCollection = service.ResolveName("SMTP:", ResolveNameSearchLocation.DirectoryOnly, true);

With this NameResolutionCollection received above, how can I know if a NameResolution.Contact is a Distribution List? I can not see any property...

Option 2. I have that, but I get contacts only from Contacts folder. That folder has a 'Recipients Cache' folder, and a GAL folder, but it is empty...

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Contacts, new ItemView(200));

Option 3. I have that, but I get all folders from Outlook (such as Notes, Outbox, Sent Items,...)

FindFoldersResults allFolders = service.FindFolders(WellKnownFolderName.Root, new FolderView(int.MaxValue) {Traversal = FolderTraversal.Deep});

Option 4. I can get all contacts from a Distribution list, but i need the name:

ExpandGroupResults results = service.ExpandGroup("[email protected]");

I have seen that FindPeople might help me (https://gsexdev.blogspot.com/2013/05/using-ews-findpeople-operation-in.html) BUT my project does not find that class (FindPeopleType, FindPeople, ...)

Any help? Is FindPeople the only way to get all contacts from my Outlook? Not only from Contacts folder

Thanks in advance, Diego

1

1 Answers

1
votes

FindPeopleType is a EWS WSDL proxy class https://blogs.msdn.microsoft.com/webdav_101/2017/12/15/about-exchange-service-xsd-and-wsdl/ and the example you posted are from the EWS Managed API (which if you used the latest version for gitHub does have FindPeople implemented but its not been done in a way that you could page the GAL). But if this is OnPrem an alternative is just use System.Directory services and LDAP to get the GAL contacts http://www.infinitec.de/post/2011/10/25/Searching-the-Global-Address-List-C-Edition.aspx or if its Office365 use the Graph API.