Microsoft Exchange Server is a well-known platform for email, calendaring and other collaboration services. Often you may need to connect to your MS Exchange Server and retrieve the list of contacts programmatically. To achieve that, this article shows how to get the contacts list from Microsoft Exchange Server in C# .NET.
- C# .NET API to Retrieve Contacts from MS Exchange Server
- Get Contacts List from MS Exchange Server
- Get a Contact using ID
C# .NET API to Get Contacts List from MS Exchange Server
To retrieve the contacts from Microsoft Exchange Server, we will use Aspose.Email for .NET. It is a powerful API that provides a range of features to implement email client applications. Also, it allows you to connect to and work with MS Exchange Server seamlessly. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Retrieve Contacts List from MS Exchange Server in C#
The following are the steps to get the contacts list from Microsoft Exchange Server in C#.
- First, initialize IEWSClient object using username, password, domain, and mailbox URI.
- Then, call IEWSClient.GetContacts(EWSClient.MailboxInfo.ContactsUri) method to get contacts in an array.
- Loop through each contact in array and fetch its details.
The following code sample shows how to get the contacts list from Microsoft Exchange Server in C#.
Get a Contact from MS Exchange Server by ID
Aspose.Email for .NET also allows you to retrieve a contact using its ID. For this, you must know the contact ID in advance. The following are the steps to retrieve a contact from MS Exchange Server in C#.
- First, initialize IEWSClient object using username, password, domain, and mailbox URI.
- Then, call IEWSClient.GetContact() method and get contact in a Contact object.
- Use or manipulate the contact as required.
The following code sample shows how to retrieve a particular contact from Microsoft Exchange Server in C#.
Get a Free API License
Get a free temporary license and use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to get the contacts list from Microsoft Exchange Server in C#. Furthermore, you have seen how to retrieve a contact by its ID programmatically. Apart from that, you can explore the other features of Aspose.Email for .NET using the documentation. Also, you can ask your questions via our forum.