Working with Folders on Exchange Server

Listing Folders

List Folders from Exchange Server

List Folders with Paging Support

For a large number of folders on Exchange Server, it might not be convenient to retrieve all the folders list at once. Aspose.Email for Java API lets you list folders from the Exchange server with paging support. The following example demonstrates the usage of this API feature.

Getting Folder Type Information using EWS

Creating Folders and Sub-Folders using EWS

Synchronizing Folder Items using EWS

Access Mailbox Custom Folders or Subfolders

In the following example, a custom folder named “TestInbox”, which is created under INBOX is accessed and all the messages are displayed from this custom folder.

To perform this task, the following are the steps:

  1. Initialize the IEWSClient object by providing valid credentials.
  2. Access the default mailbox.
  3. Access the parent folder, which is INBOX in this example. This parent folder can also be a custom folder itself.
  4. Use folderExists() to search the specified custom subfolder, for example “TestInbox”. It will return the URI of “TestInbox”.
  5. Use this Uri to access all the messages in that custom folder.  

Retrieve Folder Permissions using EWS Client

The following example shows how to use the EWSClient class to retrieve permissions applied to a folder.

To perform this task:

  1. Initialize the EWSClient.
  2. Use the listPublicFolders() to get a list of all public folders.
  3. Retrieve the permissions associated with a folder using the getFolderPermissions() method.  

Download Messages from Public Folders of Exchange Server

The sample source code below reads all public folders, and subfolders, and lists and downloads any messages found in these folders. This example only works with Microsoft Exchange Server 2007 or above since only these support EWS.

Backup Exchange Folders to PST

In order to take a backup of Exchange server folders, the following steps may be followed.

  1. Initiate the Exchange Web Service (EWS) client with user credentials.
  2. Add the required folder’s info to ExchangeFolderInfoCollection.
  3. User the client’s Backup method to export the folder’s contents to PST.