Parse Storage Files

A diverse range of email clients and platforms often leads to the creation of various email storage formats. On the one hand, these formats can pose a challenge when it comes to parsing the content. On the other hand, they are indispensable when it comes to storing data or restoring it in case of a failure with a web service. In this article, we will delve into each of these formats and demonstrate how Aspose.Email can be leveraged to extract, list, and retrieve email content of the five major file formats.

C# API to Process Storage Files

For storage files processing, we’re going to use a versatile API designed to simplify complex email-related tasks and interactions, providing a comprehensive solution for email management. Aspose.Email for .NET empowers developers to create applications that seamlessly interact with email data across a range of formats like PST, OST, MBOX, EML, MSG, and more. With its rich feature set and user-friendly methods, manipulation, extraction, and management of email data stored in files becomes easy and intuitive. To leverage the power of the API, download its DLL or install it from NuGet using the following command:

PM> Install-Package Aspose.Email

Processing Storage Files of Various TypesFormats

Reading PST (Personal Storage Table) Files

PST is a file format used by Microsoft Outlook to store emails, contacts, calendars, and other data. Aspose.Email simplifies PST file handling by providing methods to extract and retrieve items like emails, attachments, and folder structures. Using the library, developers can programmatically access PST content, search for specific items, and export them to various formats. In the code sample with steps below, you will see how to read the files in PST format:

  1. For a start, load the pst file using the FromFile method of the PersonalStorage class.
  2. Access the “Inbox” folder within the PST by using the GetSubfolder() method on the RootFolder property of the pst object.
  3. Iterate through each message in the folder using the EnumerateMessages() method on the folder object.
  4. Extract the message by using the ExtractMessage() method on the pst object, passing in the EntryIdString property of each msgInfo object.
  5. Access the contents of the message:
    • Get the subject of the message by using the Subject property of the msg object.
    • Get the from address of the message by using the SenderEmailAddress property of the msg object.
    • Get the body of the message by using the Body property of the msg object.

Reading OST (Outlook Offline Storage Table) Files

OST files serve as an offline copy of mailbox data from Microsoft Exchange. Aspose.Email enables the extraction of data from OST files, allowing developers to retrieve emails, folders, and attachments. This is particularly useful when creating backup solutions or migrating data between different platforms. The set of features, used in parsing of OST files, is identical to the one for PST, so you can use the above code sample specifying the correct path to an OST file.

Reading OLM (Outlook for Mac Archive) Files

OLM is the storage format utilized by Microsoft Outlook for Mac to store emails, contacts, and other data. With Aspose.Email, developers can extract content from OLM files, including emails and attachments. This functionality is valuable for cross-platform data migration or for creating backup systems. The following code sample and the steps will show you a way of utilizing the API to parse Outlook for Mac files:

  1. Create an instance of the OlmStorage class and load the OLM file using the constructor.
  2. Access the “Inbox” folder within the OLM by using the GetFolder() method on the olm object, passing in the folder name as “Inbox” and specifying to create the folder if it doesn’t exist.
  3. Iterate through each message in the folder using the EnumerateMessages() method on the folder object.
  4. Extract the message by using the ExtractMapiMessage() method on the olm object, passing in the msgInfo object.
  5. Access the contents of the message:
    • Get the subject of the message by using the Subject property of the msg object.
    • Get the from address of the message by using the SenderEmailAddress property of the msg object.
    • Get the body of the message by using the Body property of the msg object.

Reading MBOX (Mailbox) Files

MBOX is a widely used format for storing email messages. It is supported by many email clients and platforms. Aspose.Email enables the extraction and retrieval of emails and attachments from MBOX files, allowing developers to work with email data in a programmatic manner. Try the following code snippet to parse mbox files:

  1. Load the MBOX file using the CreateReader() method of the MboxStorageReader class with the MboxLoadOptions.
  2. Iterate through each message in the mbox using the EnumerateMessageInfo() method on the mbox object.
  3. Extract the message content from the mbox by using the ExtractMessage() method on the mbox object, passing in the EntryId and EmlLoadOptions.
  4. Access the contents of the message:
    • Get the subject of the message by using the Subject property of the eml object.
    • Get the from address of the message by using the From property of the eml object.
    • Get the body of the message by using the Body property of the eml object.

Reading TGZ (Compressed Tar Archive) Files

TGZ is a compressed archive format often used to store email backup data in Zimbra email client. Aspose.Email allows for the extraction of email content from TGZ files, making it possible to access and manipulate email data contained within these archives. The following code snippet and the steps will show you how to read tgz files:

  1. Create an instance of the TgzReader class and load the TGZ file using the constructor.
  2. Iterate through each item in the ‘Inbox’ folder using the ReadNextMessage() method on the folder object.
  3. Extract the message content from each item by using the CurrentMessage property.
  4. Perform desired actions with the extracted message content.

Conclusion

In this article, we explored how to handle storage files of the most popular formats programmatically in C#. Our intuitive code samples showed you how to implement basic capabilities in your project. Loading, listing and accessing the content of storage files is now easier with Aspose.Email for .NET. The API provides you with a seamless way to integrate email-related functionality into your .NET applications. Learn more about what the library can offer you from our documentation. Feel free to contact us on our free support forum, if you need help or advice.

See Also