Exchange Server에 연결

Exchange Web Service를 사용하여 Exchange 서버 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());
}