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
API Aspose.Email 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ỉ khả dụng trong Exchange Server 2007 và các phiên bản sau. Trong bài 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à yêu cầu cho tất cả các tính năng được mô tả trong bài.
Một cấu hình người dùng là một tập hợp tên của các cài đặt mà một ứng dụng lưu trong một thư mục của hộp thư. Nó được biểu diễn bởi một UserConfiguration đối tượng, mà từ điển của nó chứa các cài đặt dưới dạng cặp khóa-giá trị, và được xác định bằng một UserConfigurationName - tên của cấu hình và URI của thư mục.
Các mẫu trong bài viết này sử dụng các tiêu đề và không gian tên sau:
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfiguration.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfigurationName.h>
#include <Clients/Exchange/ExchangeMailboxInfo.h>
#include <system/collections/dictionary.h>
#include <system/object_ext.h>
using namespace System;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
Tất cả các ví dụ trong bài viết này kết nối tới máy chủ như sau:
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://your.exchange.server/ews/Exchange.asmx", u"username", u"password", u"domain");
client->Dispose();
Đọ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 IEWSClient.
- Gọi GetUserConfiguration() phương thức để 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ị.
Các khóa và giá trị của từ điển là các đối tượng; các chuỗi lưu trong đó được đóng gói.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
try
{
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
Console::WriteLine(u"Configuration Id: " + userConfig->get_Id());
Console::WriteLine(u"Configuration Name: " + userConfig->get_UserConfigurationName()->get_Name());
Console::WriteLine(u"Key value pairs:");
for (auto entry : userConfig->get_Dictionary())
{
Console::WriteLine(ObjectExt::ToString(entry.get_Key()) + u": " + ObjectExt::ToString(entry.get_Value()));
}
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
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 IEWSClient.
- Tạo một UserConfiguration với tên và thư mục của nó và điền vào từ điển của nó.
- Gọi CreateUserConfiguration() phương thức để tạo cấu hình người dùng cho một thư mục.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = MakeObject<UserConfiguration>(userConfigName);
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"value1"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key2"), ObjectExt::Box<String>(u"value2"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key3"), ObjectExt::Box<String>(u"value3"));
try
{
client->CreateUserConfiguration(userConfig);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
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 IEWSClient.
- Đọc cấu hình bằng GetUserConfiguration() và thay đổi từ điển của nó.
- Gọi UpdateUserConfiguration() phương thức để cập nhật cấu hình người dùng cho một thư mục.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
userConfig->get_Dictionary()->idx_set(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"new-value1"));
client->UpdateUserConfiguration(userConfig);
client->Dispose();
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 IEWSClient.
- Gọi DeleteUserConfiguration() phương thức để xóa cấu hình người dùng cho một thư mục.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
try
{
client->DeleteUserConfiguration(userConfigName);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();