管理会话项

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

查找会话

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

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

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

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find Conversation Items in the Inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
    // Display conversation properties like Id and Topic
    System.out.println("Topic: " + conversation.getConversationTopic());
    System.out.println("Flag Status: " + conversation.getFlagStatus());
    System.out.println();
}

复制会话

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

  1. 使用 IEWSClient 类连接到 Exchange Server。
  2. 调用 IEWSClient.copyConversationItems() 方法将会话项从源文件夹复制到目标文件夹。

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

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to copy
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Copy the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email")) {
        client.copyConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
        System.out.println("Copied the conversation item to another folder");
    }
}

移动会话

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

  1. 使用 IEWSClient 类连接到 Exchange Server。
  2. 调用 IEWSClient.moveConversationItems() 方法将会话从源文件夹移动到目标文件夹。

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

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to move
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());

for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Move the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email") == true) {
        client.moveConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
        System.out.println("Moved the conversation item to another folder");
    }
}

删除会话

从文件夹删除会话:

  1. 使用 IEWSClient 类连接到 Exchange Server。
  2. 调用 IEWSClient.deleteConversationItems() 方法从源文件夹删除会话项。

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

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to delete
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Delete the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email") == true) {
        client.deleteConversationItems(conversation.getConversationId());
        System.out.println("Deleted the conversation item");
    }
}