Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 28, 2022 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0879a1e9f06933f3d1105ef0dde6e026 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0879a1e9f06933f3d1105ef0dde6e026 to your computer and use it in GitHub Desktop.
Get Contacts List from Microsoft Exchange Server in C# .NET
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
string id = "<<Contact ID>>";
// Get contact
Contact fetchedContact = client.GetContact(id);
// Use or manipulate contact
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
// List all the contacts
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri);
foreach (MapiContact contact in contacts)
{
// Display name and email address
Console.WriteLine("Name: " + contact.NameInfo.DisplayName + ", Email Address: " + contact.ElectronicAddresses.Email1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment