Read MS Outlook PST Files in C# .NET

A Conversation Thread is a sequence of replies to a message with a common thread topic. Messages within conversation can be displayed in various ways, such as in hierarchical or chronological order. To display a message thread email applications identify message replies. The most popular e-mail file formats provide this feature.
Conversation threads allow readers to understand the overall structure of a conversation quickly, highlight certain points of conversations, and analyze important information. In this article we’ll focus on using the Aspose.Email’s PST/MAPI features to find and group messages by conversation. To do this, we will implement a sample code that will traverse the messages in a given folder, group them by conversation, and then save each conversation to a separate disk directory.

MAPI Properties that are used to Support the Conversation Thread

Since messages in pst are stored as a set of MAPI properties, we need to define MAPI properties which are associated with collecting message replies. This is described in the Microsoft Docs section. As it can be seen, the PidTagConversationIndex property allows to determine accurately whether a message is associated with a certain conversation or not. The property also indicates the relative message position within a conversation thread. Visit the page for more information about PidTagConversationIndex property. The header is the first 22 bytes of the PidTagConversationIndex property value. It is a data portion to determine whether the message belongs to a certain conversation thread.

C# .NET API to Read Outlook PST Files

To read PST files, we will use Aspose.Email for .NET. It is an amazing library to implement email processing apps using .NET. Using the library, you can easily handle a lot of different email file formats. You can install Aspose.Email for .NET via NuGet or download its DLL.

PM> Install-Package Aspose.Email

Group messages in PST by conversation thread

To group the messages in PST by conversations, we need the following:

  • Firstly, create a ConversationThread class. It is a container to group the messages within a conversation.
  • Then, create a method for searching and grouping messages by the conversation.
  • Finally, create a method to save the conversation thread to a separate directory.

Create a ConversationThread class

It will have the following properties.

  • Id: string representation of the conversation index header (22 bytes).
  • Messages: list of message IDs that are in the conversation thread.

Create a method for searching and grouping messages by conversation

After creating the ConversationThread class, we can focus on writing a method that does the following:

  • Go through all the messages in the folder. For performance reasons, we will only read the message identifier using EnumerateMessagesEntryId method.
  • For each message we will extract the PidTagConversationIndex property using the ExtractProperty method.
  • Messages which have the same first 22 bytes of PidTagConversationIndex property value belong to the same conversation. We will add message Id to the list represented by Messages property of the corresponding ConversationThread class instance.
  • Return the list of ConversationThread instances.

Create a method to save the conversation thread to a separate directory

Finally, let’s save the conversations in the directories.

For each ConversationThread instance, do the following:

  • Create a separate directory with the name of the thread topic.
  • Enumerate the identifiers in ConversationThread.Messages property, for each identifier extract a message using the ExtractMessage method and save the message in the created directory using Save method.

Get a Free API License

You can use Aspose.Email for .NET without evaluation limitations using a free temporary license.


This article shows how to use Aspose.Email to search for conversation-related messages in PST. By further exploring the PidTagConversationIndex documentation you can also complicate the implementation by adding, for example, hierarchical sorting of conversation messages. You can learn more about Aspose.Email using the documentation. In case you have any questions, you can post to our forum.

See Also