サーバー上でのユーザー構成の操作

ユーザー構成の管理

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 2010 に接続する方法を示しています。

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;
}

ユーザー構成の読み取り

Exchange Server から特定のフォルダーのユーザー構成情報を取得するには:

  1. IEWSClient クラスを使用して Exchange Server に接続します。
  2. フォルダーのユーザー構成を取得するには、IEWSClient.getUserConfiguration() メソッドを呼び出します。
  3. ID、名前、辞書項目などのユーザー構成プロパティをキーと値のペアとして表示します。

以下のコードスニペットは、ユーザー構成を読み取る方法を示しています。

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());
}

ユーザー構成の作成

Exchange Server 上の特定のフォルダーのユーザー構成を作成するには:

  1. IEWSClient クラスを使用して Exchange Server に接続します。
  2. フォルダーのユーザー構成を作成するには、IEWSClient.createUserConfiguration() メソッドを呼び出します。

以下のコードスニペットは、ユーザー構成を作成する方法を示しています。

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);

ユーザー構成の更新

Exchange Server の特定のフォルダーのユーザー構成を更新するには:

  1. IEWSClient クラスを使用して Exchange Server に接続します。
  2. フォルダーのユーザー構成を更新するには、IEWSClient.updateUserConfiguration() メソッドを呼び出します。

以下のコードスニペットは、ユーザー構成を更新する方法を示しています。

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);

ユーザー構成の削除

Exchange Server の特定のフォルダーのユーザー構成を削除するには:

  1. IEWSClient クラスを使用して Exchange Server に接続します。
  2. フォルダーのユーザー構成を削除するには、IEWSClient.deleteUserConfiguration() メソッドを呼び出します。

以下のコードスニペットは、ユーザー構成を削除する方法を示しています。

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);