Add, Update and Delete Contacts from Microsoft Exchange Server in C#

Add or Delete Contacts from Microsoft Exchange Server in C#

Microsoft Exchange Server is a popular platform that provides various collaboration services like email, calendars, contacts, etc. In the previous post, we have shown you how to read emails from Microsoft Exchange Server. However, you may also need to work with the contacts on the Exchange Server programmatically. In this article, you will learn how to add, delete, or update contacts on Microsoft Exchange Server in C# .NET.

C# .NET API to Access Contacts on MS Exchange Server

To work with contacts on Microsoft Exchange Server, we will use Aspose.Email for .NET. It is a well-known API to work with different email clients from within .NET applications. You can either download the API’s DLL or install it from NuGet using the following command.

PM> Install-Package Aspose.Email

Add Contacts to MS Exchange Server in C#

The following are the steps to add contacts to Microsoft Exchange Server in C#.

  • First, create and initialize NetworkCredential object with username, password, and domain.
  • Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
  • Create an object of Contact class and set its properties such as name, job, gender, phone, associated persons, etc.
  • Finally, call EWSClient.CreateContact(Contact) to add contact.

The following code sample shows how to add a contact to Microsoft Exchange Server in C#.

Delete Contacts from MS Exchange Server in C#

You can also delete a contact from the MS Exchange Server. To filter the contacts, you can use the name, email, or any other suitable property. The following are the steps to delete a contact from Microsoft Exchange Server in C#.

The following code sample shows how to delete contacts from Microsoft Exchange Server in C#.

Update a Contact on Exchange Server in C#

You can also update a contact on MS Exchange Server using Aspose.Email for .NET. The following are the steps to perform this operation.

The following code sample shows how to update a contact on MS Exchange Server in C#.

Get a Free API License

You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.

Conclusion

In this article, you have learned how to work with contacts on Microsoft Exchange Server in C#. We have demonstrated how to add, remove, and update contacts from the MS Exchange Server programmatically in C#. Besides, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.

See Also