Working with Contacts on Exchange Server

Getting Contacts with EWS

Aspose.Email provides the EWSClient class to connect to Microsoft Exchange Server using Exchange Web Services. The code snippets that follow use Exchange Web Services to read all the contacts. The following code snippet shows you how to get Contacts with EWS.

Resolve Contacts using Contact Name

The following code snippet shows you how to use get contacts with EWS

Determining Contact Notes Format

The Aspose.Email.Mail.Contact.NotesFormat specifies the contacts notes text format type defined by Aspose.Email.TextFormat enumerator.

Fetch Contact using Id

A particular contact can be retrieved from the server using its contact id as shown in the following code sample.

Adding Contacts

The EWSClient class CreateContact() method can be used to add Contact information to an Exchange Server. The CreateContact() method takes a Contact object as an input parameter.

To add contacts to an Exchange Server:

  1. Initialize the EWSClient with address and credentials.
  2. Initialize the Contact object with the desired properties.
  3. Call the CreateContact method to add the contact to the Exchange Server.

Aspose.Email provides the EWSClient class to connect to Microsoft Exchange Server using Exchange Web Services. The code snippets show you how to use Exchange Web Services to add contacts to an Exchange Server.

Updating Contacts

Contact information can be updated using Microsoft Outlook. Aspose.Email can also update contact information on Exchange Server using the Exchange Web Service (EWS). The IEWSClient UpdateContact method can update contact information on Exchange Server.

Deleting Contacts

The EWSClient class allows the DeleteContact to access and delete contacts from an Exchange Server contacts folder. This method takes the contact ID or MapiContact as an input parameter.

To delete contacts from an Exchange Server:

  1. Initialize the ExchangeWebServiceClient with address and credentials.
  2. Delete a contact using its ID.
  3. Delete a contact by calling the DeleteContact method with MapiContact as input parameter.

The following code snippets show you how to delete contacts from an exchange server using exchange web service.

Working with Extended Properties of Contacts on Exchange Server


 IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

//The required extended properties must be added in order to create or read them from the Exchange Server

string[] extraFields = new string[] {{ "User Field 1", "User Field 2", "User Field 3", "User Field 4" }};

foreach (string extraField in extraFields)

    client.ContactExtendedPropertiesDefinition.Add(extraField);

//Create a test contact on the Exchange Server

Contact contact = new Contact();

contact.DisplayName = "EMAILNET-38433 - " + Guid.NewGuid().ToString();

foreach (string extraField in extraFields)

    contact.ExtendedProperties.Add(extraField, extraField);

string contactId = client.CreateContact(contact);

//retrieve the contact back from the server after some time

Thread.Sleep(5000);

contact = client.GetContact(contactId);

//Parse the extended properties of contact

foreach (string extraField in extraFields)

    if (contact.ExtendedProperties.ContainsKey(extraField))

        Console.WriteLine(contact.ExtendedProperties[extraField].ToString());