Open PST Files & Extract Email Data in Node.js
Open and read PST files in JavaScript, accessing emails, contacts, and calendar data, and save in the desired format programmatically within Node.js applications.
PST Reader for Node.js Applications
Opening PST files and reading their content programmatically in JavaScript is easy with Aspose.Email for Node.js via .NET . It is a progressive library which provides developers with the Node.js API to manage Microsoft Outlook Personal Storage Table (PST files). The API has all the necessary tools to access, parse, and manipulate PST data. With full access to emails, contacts, calendars, and other Outlook items, Aspose.Email for Node.js via .NET simplifies complex PST management and can be a go-to solution for developers integrating Outlook data into Node.js applications.
The library saves developers countless hours by offering high-performance, ready-to-use functions that eliminate the need to develop custom parsers or data extractors.
How to Parse PST Files using Aspose.Email in Node.js
The parsing process involves just a few steps with Aspose.Email:
First, spare a minute to import Aspose.Email to access its PST file handling features via npm install aspose.email command.
Use PersonalStorage.fromFile() to open a PST file (e.g., “sample.pst”).
Retrieve the root folder of the PST file using getSubFolder() .
Use getContents() to extract all email messages in the folder.
Loop through each message and print its subject and body.
PST file parsing using Node.js via .NET
// Load the Aspose.Email library
const ae = require('@aspose/email');
// Load the PST file
const pst = ae.Storage.Pst.PersonalStorage.fromFile("sample.pst");
// Access folders
const folder = pst.rootFolder.getSubfolder("Inbox");
// List messages in the PST
const messages = folder.getContents();
messages.forEach(message => {
console.log(`Subject: ${message.subject}`);
console.log(`Body: ${message.body}`);
});
Calendar and Contact Support
Read, add, or modify calendar events and contacts stored in PST files. Try the following code that demonstrates how to access and read calendar and contact information from a PST file using the Aspose.Email library:
Node.js code sample to read Outlook calendar events and contacts
// Load the Aspose.Email library
const ae = require('@aspose/email');
// Load the PST file
const pst = ae.Storage.Pst.PersonalStorage.fromFile("somefile.pst");
// Access the Calendar and Contacts folders
const calendarFolder = pst.PersonalStorage.getPredefinedFolder(aspose.StandardIpmFolder.Appointments);
const contactsFolder = pst.PersonalStorage.getPredefinedFolder(aspose.StandardIpmFolder.Contacts);
// Read Existing Calendar Events
const calendarEvents = ae.Storage.Pst.FolderInfo.getContents();
calendarEvents.forEach(event => {
console.log(`Event Subject: ${event.subject}`);
console.log(`Start Date: ${event.startDate}`);
console.log(`End Date: ${event.endDate}`);
});
// Read Existing Contacts
const contacts = ae.Storage.Pst.FolderInfo.getContents();
contacts.forEach(contact => {
console.log(`Contact Name: ${contact.displayName}`);
console.log(`Email: ${contact.email1Address}`);
});
File Format Conversion
Convert PST data into various formats like EML, MSG, MBOX, HTML, and more, giving flexibility to work across different platforms.
- Load a PST file.
- Access its folders.
- List messages in it.
- Save the file in the desired format.
PST to MBOX conversion in Node.js via .NET
// Save as MBOX (for MBOX format, we need to add each email to an MBOX storage)
const mbox = new ae.Storage.Mbox.MboxStorageWriter("output.mbox", true);
mbox.writeMessage(message);
mbox.dispose();
About Aspose.Email Node.js API
Aspose.Email for Node.js via .NET is a powerful library that offers a robust set of tools designed to empower developers in handling email data with ease. Its extensive features include:
Managing and manipulating email messages, contacts, calendars, and other Outlook data within Node.js applications.
Working with popular email formats (like MSG, EML, and MHTML) - from email creation to parsing, conversion, and management.
While the library currently provides essential email data handling features, it’s actively developing and will include many more capabilities in future updates, further expanding its functionality.
Install Aspose.Email for Node.js via .NET
To start using Aspose.Email for PST processing, install it via npm:
Command
npm install @aspose/email
System Requirements
Before running the code, make sure you have the following prerequisites:
- Microsoft Windows or Mac OS X, Linux (Ubuntu, CentOS and others).
- Development environment like Visual Studio Code.
- Node.js version (with npm) from nodejs.org.