Add, Update and Delete Contacts from Microsoft Exchange Server in Java

Add or Delete Contacts from Microsoft Exchange Server in Java

Microsoft Exchange Server is an email and calendaring server that provides different collaboration services like email, calendars, contacts management, etc. In one of my posts, I have shown you how to access and read emails from Microsoft Exchange Server programmatically in Java. However, we often need the contact list that we have on the MS Exchange Server. So in this article, you will learn how to add, delete, or update contacts on Microsoft Exchange Server in Java.

Java API to Access Contacts on MS Exchange Server

Aspose.Email for Java is a popular API to implement email client applications in Java. Moreover, it allows you to work with MS Exchange Server and manipulate the contacts, emails, and conversation items. We will use this API to add, update, and delete contacts on Exchange Server. You can either download the API’s JAR or install it using the following Maven configurations.

Repository:
<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

Dependency:
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-email</artifactId>
    <version>22.2</version>
    <classifier>jdk16</classifier>
</dependency>

Add Contacts to MS Exchange Server in Java

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

  • 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) method to add contact.

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

Delete Contacts from MS Exchange Server in Java

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 Java.

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

Update a Contact on Exchange Server in Java

Aspose.Email for Java also allows you to update a contact on MS Exchange Server. The following are the steps to perform this operation.

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

Get a Free API License

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

Conclusion

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

See Also