Listing Messages from Exchange Server using WebDav
A list of the email messages in an Exchange mailbox can be fetched by calling the ExchangeClient.listMessages() method. Get the basic information about messages, such as subject, from, to and message ID, using the listMessages() method.
This article shows how to connect to an Exchange Server and list the emails in a mailbox directly or using WebDav. It further shows how to list messages from different folders and how to list messages by ID.
List Exchange Server Messages
To list the messages in an Exchange mailbox:
- Create an instance of the ExchangeClient class.
- Call the listMessages method and create a message collection.
- Loop through the collection and display message information.
The code snippet below connects to the Exchange mailbox and get the list of messages from the Inbox folder.
Listing Messages from Different Folders
The above code snippets list all the messages in the Inbox folder. It is possible to get the list of messages from other folders as well. The ExchangeClient.listMessages() method accepts a folder URI as a parameter. As long as the folder URI is valid, you can get the list of messages from that folder.