Làm việc với Cấu Hình Người Dùng trên Máy Chủ
Quản Lý Cấu Hình Người Dùng
Aspose.Email cho Java có thể được sử dụng để quản lý cấu hình người dùng 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. Trong bài viết này, chúng ta sẽ xem cách đọc, tạo, cập nhật và xóa cấu hình người dùng 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 mô tả trong bài viết. Đoạn mã sau cho bạn thấy cách kết nối tới Exchange Server 2010 trong tất cả các ví dụ của bài viết.
private static IEWSClient getExchangeEWSClient() {
final String mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
final String domain = "";
final String username = "username@ASE305.onmicrosoft.com";
final String password = "password";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
return client;
}
Đọc Cấu Hình Người Dùng
Để lấy thông tin cấu hình người dùng của một thư mục cụ thể từ Exchange Server:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.getUserConfiguration() để lấy cấu hình người dùng cho một thư mục.
- Hiển thị các thuộc tính cấu hình người dùng như ID, tên và các mục từ điển dưới dạng cặp khóa-giá trị.
Đoạn mã sau cho bạn thấy cách đọc cấu hình người dùng.
IEWSClient client = getExchangeEWSClient();
System.out.println("Connected to Exchange 2010");
// Get the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri());
UserConfiguration userConfig = client.getUserConfiguration(userConfigName);
System.out.println("Configuration Id: " + userConfig.getId());
System.out.println("Configuration Name: " + userConfig.getUserConfigurationName().getName());
System.out.println("Key value pairs:");
// foreach to while statements conversion
for (Object key : userConfig.getDictionary().keySet()) {
System.out.println(key + ": " + userConfig.getDictionary().get(key).toString());
}
Tạo Cấu Hình Người Dùng
Để tạo cấu hình người dùng cho 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.createUserConfiguration() để tạo cấu hình người dùng cho một thư mục.
Đoạn mã sau cho bạn thấy cách tạo cấu hình người dùng.
IEWSClient client = getExchangeEWSClient();
System.out.println("Connected to Exchange 2010");
// Create the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri());
UserConfiguration userConfig = new UserConfiguration(userConfigName);
userConfig.getDictionary().put("key1", "value1");
userConfig.getDictionary().put("key2", "value2");
userConfig.getDictionary().put("key3", "value3");
client.createUserConfiguration(userConfig);
Cập Nhật Cấu Hình Người Dùng
Để cập nhật cấu hình người dùng cho một thư mục cụ thể trong Exchange Server:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.updateUserConfiguration() để cập nhật cấu hình người dùng cho một thư mục.
Đoạn mã sau cho bạn thấy cách cập nhật cấu hình người dùng.
IEWSClient client = getExchangeEWSClient();
System.out.println("Connected to Exchange 2010");
// Create the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri());
UserConfiguration userConfig = client.getUserConfiguration(userConfigName);
userConfig.setId(null);
// Update User Configuration
userConfig.getDictionary().put("key1", "new-value1");
client.updateUserConfiguration(userConfig);
Xóa Cấu Hình Người Dùng
Để xóa cấu hình người dùng cho một thư mục cụ thể trong Exchange Server:
- Kết nối tới Exchange Server bằng lớp IEWSClient.
- Gọi phương thức IEWSClient.deleteUserConfiguration() để xóa cấu hình người dùng cho một thư mục.
Đoạn mã sau cho bạn thấy cách xóa cấu hình người dùng.
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");
// Delete User Configuration
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri());
client.deleteUserConfiguration(userConfigName);