Often, an email is composed of multiple messages (or replies) forming a thread. In Microsoft Exchange Server, these threads are termed as conversations. While working with MS Exchange Server programmatically, you may need to access and manage the conversations. To accomplish that, in this article, you will learn how to find, copy, move and delete conversations on Microsoft Exchange Server in Java.
- Java API to Work with Conversations on MS Exchange Server
- Find Conversation on MS Exchange Server in Java
- Copy a Conversation on MS Exchange Server in Java
- Move a Conversation on MS Exchange Server in Java
- Delete a Conversation on MS Exchange Server in Java
Java API to Work with Conversations on MS Exchange Server
To work with the conversations on Microsoft Exchange Server, we will use Aspose.Email for Java. It is an amazing API that provides a bunch of features to work with MS Exchange Server from within Java applications. You can either download the API 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>
Find Conversations on MS Exchange Server in Java
The following are the steps to find conversations from a folder in MS Exchange Server using Java.
- First, create and initialize the NetworkCredential object with username, password, and domain.
- Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
- Call IEWSClient.findConversations(IEWSClient.getMailboxInfo().getInboxUri()) method and get conversations in an ExchangeConversation array.
- Finally, loop through each ExchangeConversation object in the array and retrieve its details.
The following code sample shows how to find conversations from a folder in MS Exchange Server in Java.
Copy a Conversation on MS Exchange Server in Java
You can also copy the conversations from one folder to another. Let’s have a look at how to copy conversations from the inbox to deleted items folder of Exchange Server in Java.
- First, create and initialize the NetworkCredential object with username, password, and domain.
- Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
- Call IEWSClient.findConversations(IEWSClient.getMailboxInfo().getInboxUri())) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation object in the array and filter required one(s).
- Finally, copy conversation using IEWSClient.copyConversationItems(ExchangeConversation.getConversationId(), IEWSClient.getMailboxInfo().getDeletedItemsUri()) method.
The following code sample shows how to copy a conversation in MS Exchange Server using Java.
Move a Conversation on MS Exchange Server in Java
In the previous section, we just copied conversations from one folder to another. However, in certain cases, you may need to move a conversation to a particular folder. The following are the steps to move a conversation in MS Exchange Server in Java.
- First, create and initialize the NetworkCredential object with username, password, and domain.
- Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
- Call IEWSClient.findConversations(IEWSClient.getMailboxInfo().getInboxUri())) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation object in the array and filter required one(s).
- Finally, move conversation using IEWSClient.moveConversationItems(ExchangeConversation.getConversationId(), IEWSClient.getMailboxInfo().getDeletedItemsUri()) method.
The following code sample shows how to move a conversation in MS Exchange Server using Java.
Delete a Conversation on MS Exchange Server in Java
In the end, let’s have a look at how to delete a conversation from MS Exchange Server in Java.
- First, create and initialize the NetworkCredential object with username, password, and domain.
- Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
- Call IEWSClient.findConversations(IEWSClient.getMailboxInfo().getInboxUri()) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation object in the array and filter required one(s).
- Finally, delete a conversation using IEWSClient.deleteConversationItems(ExchangeConversation.getConversationId()) method.
The following code sample shows how to delete a conversation from 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 manage conversations in Microsoft Exchange Server using Java. You have seen how to find, copy, move, and delete a conversation on MS Exchange Server programmatically in Java. In addition, you can explore the documentation to read more about Aspose.Email for Java. Also, you can ask your questions via our forum.