Create PST Files in C#

PST (Personal Storage Table) files are essential for managing Outlook data, providing storage for emails, contacts, calendars, and other items. With our Node.js API, you can easily create and manage PST files, adding folders, subfolders, and various Outlook items. In this article, we’ll explore how to use the API to create PST files, add folders (standard and custom), and populate these folders with emails and Outlook items.

Node.js API for PST Files Handling

To work with Outlook storage files in JavaScript environment, we are going to use Aspose.Email for Node.js via .NET. The library is designed for JavaScript developers, offering powerful tools for processing email-related data. With its intuitive APIs, developers can effortlessly create, read, and manipulate Outlook data files, including storages. The library simplifies email message processing by providing functionalities for parsing, creating, and converting emails across various formats like MSG, EML, MHTML, and more. Aspose.Email empowers developers to efficiently manage email-related tasks within their JavaScript applications, enhancing functionality and performance while delivering superior email processing capabilities to end-users.

Getting Started with Aspose.Email for Node.js via .NET is simple. Just execute the npm install @aspose/email command to get the latest version.

Create a new PST File

Using the Create method, we can set up a minimal empty storage in Unicode format. The following Node.js code sample demonstrates how to create a new PST file called “sample.pst” using the PersonalStorage class.

Note: the minimum pst is 256 Kb, and contains a root folder and a Deleted Items folder.

Adding Folders and Subfolders

After creating an empty PST, we can add folders and subfolders for better data organization. Aspose.Email supports adding both standard (predefined) folders and custom folders.

Adding Standard Folders

Standard folders like Inbox, Sent Items, and Drafts are integral to email management. To add a standard folder, such as “Inbox,” use the CreatePredefinedFolder() method and specify the folder type as shown in the code sample below:

The predefined folder type is StandardIpmFolder.Inbox, which typically represents the Inbox folder in email clients.

Supported Standard Folders

  • Deleted Items
  • Calendar
  • Contacts
  • Journal
  • Notes
  • Tasks
  • Sync issues
  • Junk emails
  • RSS feeds

Adding Regular Folders

In addition to standard folders, you can add custom (regular) folders to your PST file. These can be added at the root or as subfolders. Below is a code sample demonstrating how to add a “Custom folder” and a subfolder under it. Provide the desired name for the subfolder as a parameter to the addSubFolder method.

  1. Use addSubFolder to add a new folder named “MyCustomFolder” to the root folder.
  2. Add a subfolder named “SubFolder” within “MyCustomFolder” using addSubFolder.

Adding Emails and Outlook Items

Once the folder structure is in place, you can start adding content like emails, contacts, and tasks. Below, we’ll demonstrate how to add an email to the “Inbox” and a contact to the “Contacts” folder using Aspose.Email for Node.js via .NET.

Adding Emails

To add an email message to a PST file, access the Inbox folder and add the newly created email message to the Inbox folder. It takes just a few simple steps:

  1. Retrieve the desired folder (e.g., “Inbox”) with the getSubFolder method.
  2. Initialize a new MapiMessage with “from” and “to” addresses, subject, and body content.
  3. Use the addMessage method to place the created message into the “Inbox” folder.

The following code sample will show you how to implement this task in Node.js:

Adding Outlook Items

Aspose.Email allows you to add a contact to a PST file by first creating a “Contacts” folder and then loading a contact from a VCF file. Follow the steps below:

  1. Use createPredefinedFolder to add a standard “Contacts” folder within the PST storage.
  2. Load the contact data from a VCF file using fromVCard.
  3. Add the loaded contact to the “Contacts” folder with addMapiMessageItem.

Try the following code sample to perform the task:

Conclusion

In this article, we covered how to create PST files using Aspose.Email for Node.js via .NET. From setting up an empty PST to adding folders, emails, and contacts, the library makes managing PST files easy and efficient. By integrating these features, developers can offer reliable Outlook data management within their Node.js applications, utilizing the rich functionality Aspose.Email provides.

Free Resources

  1. In case you encounter any difficulties while using the library, feel free to contact our Support forum for expert insights on email data management and more.

  2. Find some useful information and best practices in our blog articles.

  3. Explore detailed API documentation and examples with our API reference.

  4. Access various email tools to convert, view, merge, or analyze emails with free apps.

Maximize the potential of the API within your JavaScrips application!

See Also