Managing Conversation Items

Aspose.Email can be used to manage the conversation items on Exchange Server with the EWSClient class. This class uses Exchange Web Services, which are only available in Exchange Server 2007 and later releases. This article shows how to find, copy, move and delete conversation items on Exchange Server 2010. Microsoft Exchange Server 2010 Service Pack 1 is required for all the features included in this section.

Finding Conversations

To get the conversation information from a specific folder on the Exchange Server:

  1. Connect to the Exchange Server using the IEWSClient class.
  2. Call the FindConversations() method to find all the conversation items in a folder.
  3. Display the conversation item properties like ID, conversation topic and flag status.

The following code snippet shows you how to find conversations.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
// Find Conversation Items in the Inbox folder
System::ArrayPtr<System::SharedPtr<ExchangeConversation>> conversations = client->FindConversations(client->get_MailboxInfo()->get_InboxUri());
// Show all conversations
for (System::SharedPtr<ExchangeConversation> conversation : conversations)
{
// Display conversation properties like Id and Topic
System::Console::WriteLine(System::String(u"Topic: ") + conversation->get_ConversationTopic());
System::Console::WriteLine(System::String(u"Flag Status: ") + System::ObjectExt::ToString(conversation->get_FlagStatus()));
System::Console::WriteLine();
}

Copying Conversations

To copy conversations from one folder to another:

  1. Connect to the Exchange Server using the IEWSClient class.
  2. Call the CopyConversationItems() method to copy the conversation item from the source folder to the destination folder.

The following code snippet shows you how to copy conversations.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
System::Console::WriteLine(u"Connected to Exchange 2010");
try
{
// Find those Conversation Items in the Inbox folder which we want to copy
System::ArrayPtr<System::SharedPtr<ExchangeConversation>> conversations = client->FindConversations(client->get_MailboxInfo()->get_InboxUri());
for (System::SharedPtr<ExchangeConversation> conversation : conversations)
{
System::Console::WriteLine(System::String(u"Topic: ") + conversation->get_ConversationTopic());
// Copy the conversation item based on some condition
if (conversation->get_ConversationTopic().Contains(u"test email") == true)
{
client->CopyConversationItems(conversation->get_ConversationId(), client->get_MailboxInfo()->get_DeletedItemsUri());
System::Console::WriteLine(u"Copied the conversation item to another folder");
}
}
}

Moving Conversations

To move conversations from one folder to another:

  1. Connect to the Exchange Server using the IEWSClient class.
  2. Call the MoveConversationItems() method to move a conversation from the source folder to the destination folder.

The following code snippet shows you how to move conversations.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
System::Console::WriteLine(u"Connected to Exchange 2010");
try
{
// Find those Conversation Items in the Inbox folder which we want to move
System::ArrayPtr<System::SharedPtr<ExchangeConversation>> conversations = client->FindConversations(client->get_MailboxInfo()->get_InboxUri());
for (System::SharedPtr<ExchangeConversation> conversation : conversations)
{
System::Console::WriteLine(System::String(u"Topic: ") + conversation->get_ConversationTopic());
// Move the conversation item based on some condition
if (conversation->get_ConversationTopic().Contains(u"test email") == true)
{
client->MoveConversationItems(conversation->get_ConversationId(), client->get_MailboxInfo()->get_DeletedItemsUri());
System::Console::WriteLine(u"Moved the conversation item to another folder");
}
}
}
catch (System::Exception& ex)
{
System::Console::WriteLine(ex.get_Message());
}

Deleting Conversations

To delete conversations from a folder:

  1. Connect to the Exchange Server using the IEWSClient class.
  2. Call the DeleteConversationItems() method to delete the conversation item from the source folder.

The following code snippet shows you how to delete conversations.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
System::Console::WriteLine(u"Connected to Exchange 2010");
try
{
// Find those Conversation Items in the Inbox folder which we want to delete
System::ArrayPtr<System::SharedPtr<ExchangeConversation>> conversations = client->FindConversations(client->get_MailboxInfo()->get_InboxUri());
for (System::SharedPtr<ExchangeConversation> conversation : conversations)
{
System::Console::WriteLine(System::String(u"Topic: ") + conversation->get_ConversationTopic());
// Delete the conversation item based on some condition
if (conversation->get_ConversationTopic().Contains(u"test email") == true)
{
client->DeleteConversationItems(conversation->get_ConversationId());
System::Console::WriteLine(u"Deleted the conversation item");
}
}
}
catch (System::Exception& ex)
{
System::Console::WriteLine(ex.get_Message());
}