การจัดการรายการสนทนา
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:
- เชื่อมต่อกับ Exchange Server โดยใช้คลาส IEWSClient.
- เรียกเมธอด IEWSClient.findConversations() เพื่อค้นหารายการสนทนาทั้งหมดจากโฟลเดอร์.
- แสดงคุณสมบัติของรายการสนทนา เช่น 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();
}
การคัดลอกการสนทนา
เพื่อคัดลอกการสนทนาจากโฟลเดอร์หนึ่งไปยังอีกโฟลเดอร์:
- เชื่อมต่อกับ Exchange Server โดยใช้คลาส IEWSClient.
- เรียกเมธอด 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");
}
}
การย้ายการสนทนา
เพื่อย้ายการสนทนาจากโฟลเดอร์หนึ่งไปยังอีกโฟลเดอร์:
- เชื่อมต่อกับ Exchange Server โดยใช้คลาส IEWSClient.
- เรียกเมธอด 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");
}
}
การลบการสนทนา
เพื่อลบการสนทนาจากโฟลเดอร์:
- เชื่อมต่อกับ Exchange Server โดยใช้คลาส IEWSClient.
- เรียกเมธอด 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");
}
}