The conversations on Microsoft Exchange Server are referred to as the group of email messages in a thread. In simple words, an email and all its replies are known to be a conversation. In this article, we will show you how to work with conversations in MS Exchange Server programmatically. Particularly, you will learn how to find, copy, move and delete conversations on MS Exchange Server in C# .NET.
- C# .NET API to Work with Conversations on MS Exchange Server
- Find Conversations on MS Exchange Server in C#
- Copy a Conversation on MS Exchange Server in C#
- Move a Conversation on MS Exchange Server in C#
- Delete a Conversation on MS Exchange Server in C#
C# .NET API to Work with Conversations on MS Exchange Server
To manage the conversations on Microsoft Exchange Server, we will use Aspose.Email for .NET. It is a powerful API that provides a range of features to implement email client applications. Also, it allows you to access various services of MS Exchange Server seamlessly. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Find Conversations on MS Exchange Server in C#
The following are the steps to find conversations from a folder in MS Exchange Server in C#.
- 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.MailboxInfo.InboxUri) 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 C#.
Copy a Conversation on MS Exchange Server in C#
You can also copy the conversations from one folder to another without writing a complex code. For demonstration, let’s have a look at how to copy conversations from the inbox to deleted items folder of Exchange Server in C# .NET.
- 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.MailboxInfo.InboxUri) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation in the array and filter the required one(s).
- Finally, copy conversation using IEWSClient.CopyConversationItems(ExchangeConversation.ConversationId, client.MailboxInfo.DeletedItemsUri) method.
The following code sample shows how to copy a conversation in MS Exchange Server using C# .NET.
Move a Conversation on MS Exchange Server in C#
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 conversations in MS Exchange Server in C# .NET.
- 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.MailboxInfo.InboxUri) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation in the array and filter the required one(s).
- Finally, move conversation using IEWSClient.MoveConversationItems(ExchangeConversation.ConversationId, client.MailboxInfo.DeletedItemsUri) method.
The following code sample shows how to move a conversation in MS Exchange Server using C# .NET.
Delete a Conversation on MS Exchange Server in C#
Last but not the least, let’s have a look at how to delete a conversation from MS Exchange Server in C#.
- First, create and initialize the NetworkCredential object with username, password, and domain.
- Then, initialize IEWSClient with mailbox URI and NetworkCredential object.
- After that, call IEWSClient.FindConversations(IEWSClient.MailboxInfo.InboxUri) method and get conversations in an ExchangeConversation array.
- Loop through each ExchangeConversation in the array and filter the required one(s).
- Finally, delete a conversation using IEWSClient.DeleteConversationItems(ExchangeConversation.ConversationId) method.
The following code sample shows how to delete a conversation from MS Exchange Server in C# .NET.
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 manage conversations in Microsoft Exchange Server using C#. You have seen how to find, copy, move, and delete conversations on MS Exchange Server programmatically in C#. In addition, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.