Quản Lý Các Mục Cuộc Trò Chuyện
Aspose.Email cho Java có thể được sử dụng để quản lý các mục cuộc trò chuyện trên Exchange Server với EWSClient lớp. Lớp này sử dụng Exchange Web Services, chỉ có sẵn trong Exchange Server 2007 và các phiên bản sau. Bài viết này cho thấy cách tìm, sao chép, di chuyển và xóa các mục cuộc trò chuyện trên Exchange Server 2010. Microsoft Exchange Server 2010 Service Pack 1 là bắt buộc cho tất cả các tính năng được bao gồm trong phần này.
Tìm Kiếm Các Cuộc Trò Chuyện
Để lấy thông tin cuộc trò chuyện từ một thư mục cụ thể trên Exchange Server:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.findConversations() để tìm tất cả các mục cuộc trò chuyện từ một thư mục.
- Hiển thị các thuộc tính của mục cuộc trò chuyện như ID, chủ đề cuộc trò chuyện và trạng thái cờ.
Đoạn mã sau cho bạn thấy cách tìm các cuộc trò chuyện.
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();
}
Sao Chép Các Cuộc Trò Chuyện
Để sao chép các cuộc trò chuyện từ thư mục này sang thư mục khác:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.copyConversationItems() để sao chép mục cuộc trò chuyện từ thư mục nguồn tới thư mục đích.
Đoạn mã sau cho bạn thấy cách sao chép các cuộc trò chuyện.
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");
}
}
Di Chuyển Các Cuộc Trò Chuyện
Để di chuyển các cuộc trò chuyện từ thư mục này sang thư mục khác:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.moveConversationItems() để di chuyển một cuộc trò chuyện từ thư mục nguồn tới thư mục đích.
Đoạn mã sau cho bạn thấy cách di chuyển các cuộc trò chuyện.
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");
}
}
Xóa Các Cuộc Trò Chuyện
Để xóa các cuộc trò chuyện từ một thư mục:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.deleteConversationItems() để xóa mục cuộc trò chuyện từ thư mục nguồn.
Đoạn mã sau cho bạn thấy cách xóa các cuộc trò chuyện.
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");
}
}