EWS を使用して Exchange Server のユーザー構成を管理する
Contents
[
Hide
]
Aspose.Email for .NET は、次を使用して Exchange Server 上のユーザー構成を管理できます EWSClient クラス。このクラスは Exchange Web Services を使用しますが、これは Exchange Server 2007 以降でのみ利用可能です。本記事では、Exchange Server 2010 でユーザー構成の読み取り、作成、更新、削除を行う方法を示します。この記事で説明するすべての機能には Microsoft Exchange Server 2010 Service Pack 1 が必要です。以下のコードスニペットは、この記事のすべての例で Exchange Server 2010 に接続する方法を示しています。
private static IEWSClient GetExchangeEWSClient()
{
const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
const string domain = @"";
const string username = @"username@ASE305.onmicrosoft.com";
const string password = @"password";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
return client;
}
ユーザー構成の読み取り
Exchange Server から特定のフォルダーのユーザー構成情報を取得するには:
- 次を使用して Exchange Server に接続する IEWSClient インターフェイス。
- 呼び出す IEWSClient.GetUserConfiguration() フォルダーのユーザー構成を取得するメソッド。
- ID、名前、辞書項目などのユーザー構成プロパティをキーと値のペアとして表示します。
以下のコードスニペットは、ユーザー構成を読み取る方法を示しています。
IEWSClient client = GetExchangeEWSClient();
Console.WriteLine("Connected to Exchange 2010");
// Get the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri);
UserConfiguration userConfig = client.GetUserConfiguration(userConfigName);
Console.WriteLine("Configuration Id: " + userConfig.Id);
Console.WriteLine("Configuration Name: " + userConfig.UserConfigurationName.Name);
Console.WriteLine("Key value pairs:");
foreach (string key in userConfig.Dictionary.Keys)
{
Console.WriteLine(key + ": " + userConfig.Dictionary[key].ToString());
}
ユーザー構成の作成
Exchange Server 上の特定のフォルダーのユーザー構成を作成するには:
- 次を使用して Exchange Server に接続する IEWSClient インターフェイス。
- 呼び出す IEWSClient.CreateUserConfiguration() フォルダーのユーザー構成を作成するメソッド。
以下のコードスニペットは、ユーザー構成の作成方法を示しています。
IEWSClient client = GetExchangeEWSClient();
Console.WriteLine("Connected to Exchange 2010");
// Create the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri);
UserConfiguration userConfig = new UserConfiguration(userConfigName);
userConfig.Dictionary.Add("key1", "value1");
userConfig.Dictionary.Add("key2", "value2");
userConfig.Dictionary.Add("key3", "value3");
client.CreateUserConfiguration(userConfig);
ユーザー構成の更新
Exchange Server の特定のフォルダーのユーザー構成を更新するには:
- 次を使用して Exchange Server に接続する IEWSClient インターフェイス。
- 呼び出す IEWSClient.UpdateUserConfiguration() フォルダーのユーザー構成を更新するメソッド。
以下のコードスニペットは、ユーザー構成を更新する方法を示しています。
IEWSClient client = GetExchangeEWSClient();
Console.WriteLine("Connected to Exchange 2010");
// Create the User Configuration for Inbox folder
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri);
UserConfiguration userConfig = client.GetUserConfiguration(userConfigName);
userConfig.Id = null;
// Update User Configuration
userConfig.Dictionary["key1"] = "new-value1";
client.UpdateUserConfiguration(userConfig);
ユーザー構成の削除
Exchange Server の特定のフォルダーのユーザー構成を削除するには:
- 次を使用して Exchange Server に接続する IEWSClient インターフェイス。
- 呼び出す IEWSClient.DeleteUserConfiguration() フォルダーのユーザー構成を削除するメソッド。
以下のコードスニペットは、ユーザー構成を削除する方法を示しています。
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
Console.WriteLine("Connected to Exchange 2010");
// Delete User Configuration
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri);
client.DeleteUserConfiguration(userConfigName);