在 Exchange Server 上管理会话项目

Aspose.Email for .NET 可用于使用以下方式在 Exchange Server 上管理会话项目: EWSClient 类。此类使用 Exchange Web Services,仅在 Exchange Server 2007 及更高版本中可用。本文展示了如何 查找, 复制, 移动 和 删除 Exchange Server 2010 上的会话项。本节所有功能均需 Microsoft Exchange Server 2010 Service Pack 1。

查找会话

从 Exchange Server 上的特定文件夹获取会话信息:

  1. 使用以下方式连接到 Exchange Server: IEWSClient 接口。
  2. 调用 IEWSClient.FindConversations() 查找文件夹中所有会话项目的方法。
  3. 显示会话项属性,例如 ID、会话主题和标记状态。

下面的代码片段展示了如何查找会话。

IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
Console.WriteLine("Connected to Exchange 2010"); 
            
// Find Conversation Items in the Inbox folder
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);
// Show all conversations
foreach (ExchangeConversation conversation in conversations)
{
    // Display conversation properties like Id and Topic
    Console.WriteLine("Topic: " + conversation.ConversationTopic);
    Console.WriteLine("Flag Status: " + conversation.FlagStatus.ToString());
    Console.WriteLine();
}

复制会话

将会话从一个文件夹复制到另一个文件夹:

  1. 使用以下方式连接到 Exchange Server: IEWSClient 接口。
  2. 调用 IEWSClient.CopyConversationItems() 将会话项目从源文件夹复制到目标文件夹的方法。

下面的代码片段展示了如何复制会话。

IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
Console.WriteLine("Connected to Exchange 2010");
            
// Find those Conversation Items in the Inbox folder which we want to copy
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);
foreach (ExchangeConversation conversation in conversations)
{
    Console.WriteLine("Topic: " + conversation.ConversationTopic);
    // Copy the conversation item based on some condition
    if (conversation.ConversationTopic.Contains("test email") == true)
    {
        client.CopyConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri);
        Console.WriteLine("Copied the conversation item to another folder");
    }
}

移动会话

将会话从一个文件夹移动到另一个文件夹:

  1. 使用以下方式连接到 Exchange Server: IEWSClient 接口。
  2. 调用 IEWSClient.MoveConversationItems() 将会话从源文件夹移动到目标文件夹的方法。

下面的代码片段展示了如何移动会话。

IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
Console.WriteLine("Connected to Exchange 2010");
            
// Find those Conversation Items in the Inbox folder which we want to move
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);

foreach (ExchangeConversation conversation in conversations)
{
    Console.WriteLine("Topic: " + conversation.ConversationTopic);
    // Move the conversation item based on some condition
    if (conversation.ConversationTopic.Contains("test email") == true)
    {
        client.MoveConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri);
        Console.WriteLine("Moved the conversation item to another folder");
    }
}

删除会话

从文件夹删除会话:

  1. 使用以下方式连接到 Exchange Server: IEWSClient 接口。
  2. 调用 IEWSClient.DeleteConversationItems() 删除源文件夹中会话项目的方法。

下面的代码片段展示了如何删除会话。

IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
Console.WriteLine("Connected to Exchange 2010");
            
// Find those Conversation Items in the Inbox folder which we want to delete
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);
foreach (ExchangeConversation conversation in conversations)
{
    Console.WriteLine("Topic: " + conversation.ConversationTopic);
    // Delete the conversation item based on some condition
    if (conversation.ConversationTopic.Contains("test email") == true)
    {
        client.DeleteConversationItems(conversation.ConversationId);
        Console.WriteLine("Deleted the conversation item");
    }
}