View messages from desired folders in Outlook Data Files (OST/PST)

Hello everyone! Today, I am quite excited to announce that GroupDocs.Viewer for Java 19.8 has been released with 20+ new features, improvements, and bug fixes. Although every new feature in this version has its own importance, I have picked a few interesting but useful features for you. So in this post, I am going to give you an overview of how to work with the folders contained by Outlook Data Files (OST/PST) and use the message filters to render selective Outlook messages.

In the previous versions of the API, we already have the feature of rendering all the messages from the Outlook Data Files. But there could be the case when you need to render the messages from a specified folder. Also, what if you want to render the only messages you have received from a particular email address? These are the questions that I’ll answer today.

First of all, let me give you a brief overview of the Outlook Data Files and the message folders.

The Outlook uses OST and PST files to store the local copy of all the information when you set up your email account. Have a look at how Microsoft defines both of these data files:

Outlook Data File (.pst) – An Outlook Data File (.pst) contains your messages and other Outlook items and is saved on your computer.

Offline Outlook Data File (.ost) – Most other account types, such as IMAP accounts, Office 365 accounts, Exchange accounts, and Outlook.com accounts use an Offline Outlook Data File (.ost) file to store a synchronized copy of your mailbox information on your local computer.
(read more)

Microsoft

Now let’s come to the Outlook folders. MS Outlook manages your messages in different folders such as Inbox for incoming messages, Sent items for the messages you send and so on. Along with the default message folders, you can also create new folders to organize the messages in the way you want. For example, you can create a separate folder to keep the messages from a particular organization or a person. Have a look at the following image which shows different folders in the Outlook:

Now you would have got the idea of Outlook Data Files and the folder they contain. Let’s move on to the features that we have introduced to deal with the Outlook folders and the messages.

Retrieving the list of Outlook folders

Before rendering the messages from a specific folder, you must know the names of all the folders the data file contains. Once you have got the list, you can select a folder and render the messages from it. For this, the API provides OutlookDocumentInfoContainer.getFolders() method which returns a list of the folder names. This is how you can do it using the code:

There might be the case when you want to get the list of subfolders from a specific folder e.g. Inbox. In that case, you just need to specify the folder’s name using DocumentInfoOptions.getOutlookOptions().setFolderName() and the rest of the code will remain the same.

Rendering messages from a specified folder

Now when you have got the list of the folders, you can render the messages from a particular folder. This is again as easy as pie. Just mention the folder’s name in the HtmlOptions or ImageOptions and call getPages() method. Have a look at the complete code:

In case you want to render the folder’s content as a PDF document, you will specify the folder’s name in PdfFileOptions and call the getPdfFile() method (as shown below).

This is what you would get in the rendering result:

Filtering messages to be rendered

Another important feature we have introduced is filtering the messages that you want to render. With this feature, you can select the messages by applying the following filters:

  • Text filter – To filter messages by subject and content of the message.
  • Address Filter – To filter messages by sender’s and recipient’s email addresses.

You can set these filters using setTextFilter() and setAddressFilter() methods of HtmlOptions, ImageOptions, and PdfFileOptions classes. Suppose, you want to render all the messages that contain the word ‘Susan’ in the subject or the body. In that case, you will set the text filter to ‘Susan’ in the following way:

Similarly, you can apply the address filter to get the messages based on the sender’s or the recipient’s email address.

Well, you have seen how easy it is to view the folders as well as the messages from the Outlook Data Files using GroupDocs.Viewer for Java 19.8. This is it from my side. For a full list of new features, improvements, and fixes, please have a look at the release notes. Try out the API features yourself by downloading and running the examples project. For more details on each feature of the API, have a look at the documentation.

As always we look forward to connecting with you via the GroupDocs Forum.