WebDav を使用した Exchange Server の連絡先操作

Exchange Server から連絡先を取得

この ExchangeClient クラス listContacts() このメソッドは Exchange Server から連絡先情報を取得するために使用できます。 listContacts() このメソッドは Contacts フォルダーの URI を必要とし、これは簡単に取得できます。 ExchangeMailboxInfo.ContactsUri プロパティです。

Exchange Server から連絡先を取得するには:

  1. アドレスと認証情報で ExchangeClient クラスを初期化します。
  2. ExchangeClient.getMailboxInfo().getContactsUri() プロパティを使用して、Contacts フォルダーの URI を取得します。
  3. listContacts() メソッドを呼び出します。これにより MapiContact の配列が返されます。
  4. MapiContact 配列に対して foreach ループを実行し、連絡先情報を読み取ります。

以下のコードスニペットは、使用方法を示しています ExchangeClient Exchange Server からすべての連絡先を読み取るクラスです。

String mailboxURI = "http://ex2003/exchange/administrator"; // WebDAV
String username = "administrator";
String password = "pwd";
String domain = "domain.local";

// Credentials for connecting to Exchange Server
NetworkCredential credential = new NetworkCredential(username, password, domain);
ExchangeClient client = new ExchangeClient(mailboxURI, credential);

// List all the contacts
MapiContact[] contacts = client.listContacts(client.getMailboxInfo().getContactsUri());
for (MapiContact contact : contacts)
{
    // Display name and email address
    System.out.println("Name: " + contact.getNameInfo().getDisplayName() + ", Email Address: " + contact.getElectronicAddresses().getEmail1());
}