Mengelola Item Percakapan

Aspose.Email untuk Java dapat digunakan untuk mengelola item percakapan pada Exchange Server dengan EWSClient kelas. Kelas ini menggunakan Exchange Web Services, yang hanya tersedia di Exchange Server 2007 dan rilis selanjutnya. Artikel ini menunjukkan cara temukan, salin, pindahkan dan hapus item percakapan pada Exchange Server 2010. Microsoft Exchange Server 2010 Service Pack 1 diperlukan untuk semua fitur yang termasuk dalam bagian ini.

Menemukan Percakapan

Untuk mendapatkan informasi percakapan dari folder tertentu di Exchange Server:

  1. Terhubung ke Exchange Server menggunakan kelas IEWSClient.
  2. Panggil metode IEWSClient.findConversations() untuk menemukan semua item percakapan dari sebuah folder.
  3. Tampilkan properti item percakapan seperti ID, topik percakapan, dan status flag.

Potongan kode berikut menunjukkan cara menemukan percakapan.

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();
}

Menyalin Percakapan

Untuk menyalin percakapan dari satu folder ke folder lain:

  1. Terhubung ke Exchange Server menggunakan kelas IEWSClient.
  2. Panggil metode IEWSClient.copyConversationItems() untuk menyalin item percakapan dari folder sumber ke folder tujuan.

Potongan kode berikut menunjukkan cara menyalin percakapan.

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");
    }
}

Memindahkan Percakapan

Untuk memindahkan percakapan dari satu folder ke folder lain:

  1. Terhubung ke Exchange Server menggunakan kelas IEWSClient.
  2. Panggil metode IEWSClient.moveConversationItems() untuk memindahkan percakapan dari folder sumber ke folder tujuan.

Potongan kode berikut menunjukkan cara memindahkan percakapan.

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");
    }
}

Menghapus Percakapan

Untuk menghapus percakapan dari sebuah folder:

  1. Terhubung ke Exchange Server menggunakan kelas IEWSClient.
  2. Panggil metode IEWSClient.deleteConversationItems() untuk menghapus item percakapan dari folder sumber.

Potongan kode berikut menunjukkan cara menghapus percakapan.

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");
    }
}