Extracting specific properties can be very helpful when working with message files. It means reading and retrieving particular pieces of data from a message object or a file (email, chat message, system event, etc.) rather than processing the whole message. This lets programs access just the fields they need (for indexing, filtering, display, analytics, or routing) while ignoring the rest. This feature is useful for developers building high-performance applications that need to scan, analyze, or report on large mailboxes. Extracting every single message fully just to get a subject, an attachment name, or a recipient list is inefficient and consumes significant memory.

Aspose.Email for .NET allows you to implement this feature into your project with its powerful APIs. It has a comprehensive set of components to work with PST files, and much more.

In this article, we will demonstrate how to extract specific properties, all attachments, and the recipient list from messages within a PST file using C#. And we will not need to load the entire MAPI items.

What You Need to Get Started

To work with Outlook storage files in C#, we’ll use the Aspose.Email for .NET library. It allows you to handle email messages, attachments, folders, templates, and much more without relying on Microsoft Outlook or other external dependencies. You can install it via NuGet or by using the following command in the NuGet Package Manager console:

PM> Install-Package Aspose.Email

Get a temporary license to evaluate the library without limitations.

Extract Specific Properties using Property Tags

The PersonalStorage class is the primary API for working with PST files which includes the efficient ExtractProperty method. ExtractProperty retrieves a single MAPI property by its numeric tag (returning null if absent). It is perfect to perform quick checks of values like PRSUBJECT, PRSENTREPRESENTINGNAME, or PRCREATIONTIME. Use KnownPropertyList to obtain well-known property tags, then call ExtractProperty with a message EntryId to read only the needed fields without loading the full message.

*Property tags are integers that identify a MAPI property. Aspose.Email provides the KnownPropertyList class to access these tags easily.

Code sample

The following C# code shows how to open a PST file, iterate through messages in a folder, and extract just the subject and sender’s email address for each message:

Explanation

This code demonstrates PST scan with minimal resource use. Instead of using pst.ExtractMessage(messageInfo) to get the full MapiMessage object (which contains all properties, the body, and attachments), we extract only two specific properties. The ExtractProperty method accesses the PST storage layer directly to retrieve just the requested data bytes. This approach is fast and takes up minimal memory. It is also perfect for generating reports or statistics from large folders quickly. The null-conditional operator (?.) and the null-coalescing operator (??) are used to handle cases where a message might not have the requested property.

Download Attachments

Downloading all attachments from a message is another common scenario. Instead of extracting the whole message and then accessing its attachments collection, you can use the dedicated ExtractAttachments method. This method returns a MapiAttachmentCollection for a given message EntryId, allowing you to save each attachment directly to disk.

Code sample

Here is how to extract and save all attachments from a specific message:

Explanation

The key advantage of using ExtractAttachments is efficiency. A full message extraction would decode and load the entire message structure into memory, including its body and all properties, just to get to the attachments. This method bypasses all that unnecessary processing. It goes directly to the attachment data within the PST entry for that message and reconstructs only the attachment objects. This is much faster and consumes less memory, especially if the message body is large (e.g., HTML with embedded images) but you are only interested in saving the attached files. You would typically get the targetEntryId from a previous enumeration of a folder, as shown in the first example.

Retrieve Recipient Lists

Similarly, you might need to get the list of To, Cc, and Bcc recipients for a message without processing its body or other properties. The ExtractRecipients method serves this purpose perfectly. It returns a MapiRecipientCollection for the specified message EntryId.

Code sample

The code snippet below demonstrates how to extract and display the recipients of a message:

Explanation

This method follows the same principle as the others. Recipient information is stored as a separate item within the message. ExtractRecipients parses only this specific part of the message data. This is ideal for tasks like building a contact list from all sent emails, analyzing communication patterns, or auditing who was included in specific discussions. The RecipientType property (of type MapiRecipientType) tells you if the recipient was a primary To address, was CC, or was a hidden BCC recipient, providing valuable context for your application.

Conclusion

We’ve guided you through the most common components and use cases that help bypass loading the entire MAPI message to get its specific properties. You can use this approach to build high-performance .NET applications that need to quickly scan, analyze, or report on large mailboxes with a minimal memory footprint.

We encourage you to integrate these best practices into your own projects. Download the Aspose.Email for .NET library today from NuGet and discover how easy it is to harness the full potential of your PST files without unnecessary overhead.

Try also our free resources:

  • API reference offers in-depth information on classes and methods.
  • Documentation provides comprehensive guides with examples.
  • Support forum allows users to seek help and discuss issues.
  • Blog features updates, tutorials, and best practices.

See Also