Exchange Server への接続

Exchange Web Service を使用して Exchange Server 2007、2010、2013 に接続するために、Aspose.Email は IEWSClient インターフェースは次の機能を実装します。 EWSClient クラス。 EWSClient.getEWSClient メソッドはインスタンス化して返します。 IEWSClient このオブジェクトは、Exchange メールボックスや他のフォルダーに関連する操作を実行するために使用されます。本記事では、以下のオブジェクトのインスタンス化方法を示します。 IEWSClient.

EWS を使用した Exchange Server への接続

次のコードスニペットは、Exchange Web Service (EWS) を使用して接続する方法を示します。

private static IEWSClient getExchangeEWSClient() {
    final String mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
    final String domain = "";
    final String username = "username@onmicrosoft.com";
    final String password = "password";
    NetworkCredential credentials = new NetworkCredential(username, password, domain);
    IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
    return client;
}

IMAP を使用した Exchange Server への接続

Microsoft Exchange Server は、メールボックス内のアイテムへアクセスするために IMAP プロトコルをサポートしています。Aspose.Email の ImapClient IMAP プロトコルを使用して Exchange Server に接続するクラスです。詳細については、 ImapClient クラスです。まず、Exchange Server で IMAP サービスが有効になっていることを確認してください:

  1. コントロール パネルを開きます。
  2. 管理ツールに移動し、次にサービスを開きます。
  3. Microsoft Exchange IMAP4 サービスのステータスを確認してください。
  4. まだ実行されていない場合は、有効に/開始してください。

次のコードスニペットは、IMAP プロトコルを使用して Microsoft Exchange Server の受信トレイフォルダーに接続し、メッセージを一覧表示する方法を示します。

// Connect to Exchange Server using ImapClient class
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1");
imapClient.setSecurityOptions(SecurityOptions.Auto);

// Select the Inbox folder
imapClient.selectFolder(ImapFolderInfo.IN_BOX);

// Get the list of messages
ImapMessageInfoCollection msgCollection = imapClient.listMessages();
for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
    System.out.println(msgInfo.getSubject());
}
// Disconnect from the server
imapClient.dispose();

次のコードスニペットは、SSL の使用方法を示します。

public static void run() {
    // Connect to Exchange Server using ImapClient class
    ImapClient imapClient = new ImapClient("ex07sp1", 993, "Administrator", "Evaluation1");
    imapClient.setSecurityOptions(SecurityOptions.SSLExplicit);

    // Select the Inbox folder
    imapClient.selectFolder(ImapFolderInfo.IN_BOX);

    // Get the list of messages
    ImapMessageInfoCollection msgCollection = imapClient.listMessages();
    for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
        System.out.println(msgInfo.getSubject());
    }
    // Disconnect from the server
    imapClient.dispose();
}

IMAP を使用して Exchange サーバーに接続し、取得した後、 IMapMessageInfoCollection、次のコードスニペットは、以下の使い方を示します。 MessageInfo オブジェクトのシーケンス番号で特定のメッセージを保存します。

// Select the Inbox folder
imapClient.selectFolder(ImapFolderInfo.IN_BOX);
// Get the list of messages
ImapMessageInfoCollection msgCollection = imapClient.listMessages();
for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
    // Fetch the message from inbox using its SequenceNumber from msgInfo
    MailMessage message = imapClient.fetchMessage(msgInfo.getSequenceNumber());

    // Save the message to disc now
    message.save(dataDir + msgInfo.getSequenceNumber() + "_out.msg", SaveOptions.getDefaultMsgUnicode());
}