Aspose.Email  for Node.js via .NET

Read OLM Files in JavaScript

Open and read OLM files in JavaScript, accessing emails and other data, saving to PST format programmatically within Node.js applications.

OLM Reader for Node.js Applications

Aspose.Email for Node.js via .NET offers a reliable solution for developers aiming to work with OLM files in Node.js environments. OLM files, used by Microsoft Outlook for Mac, often require specialized tools to access their content on other platforms. This JavaScript API provides developers with such tools to easily open OLM files, extract data, and parse content without the need for a separate conversion tool. From emails and calendar events to contacts and attachments, Aspose.Email enables full access to all OLM data in a way that is both intuitive and efficient.

The APIs save developers countless hours by offering high-performance, ready-to-use functions that eliminate the need to develop custom parsers or data extractors.

Read OLM Files with Aspose.Email in Node.js

The API provides structured access to each component within an OLM file, making it easy to retrieve individual items such as emails, contact lists, and tasks with a few lines of code. Test the following code sample demonstrating how to open an OLM file and read email messages using the Node.js API.

Steps to Read an OLM File

Before you start, spare a minute to import Aspose.Email to access its OLM file handling features via npm install aspose.email command. The evaluation version or a temporary license are available for free.

  1. Load the OLM file using the OlmStorage.fromFile() method.
  2. Access the “Inbox” folder in the file. The true argument ensures the search includes subfolders if they exist.
  3. Loop through messages in the folder with the enumerateMessages() .
  4. Check if the message date is today’s date. Only messages received today will proceed to the next step.
  5. Extract today’s messages from the Inbox. For each message matching today’s date, extractMapiMessage() retrieves the full message data, creating a MapiMessage object (msg) for further use.

Code Sample

 

OLM file parsing using Node.js via .NET

// Import the Aspose.Email library
const ae = require('@aspose/email');

const ae = require('@aspose/email');

// Load the OLM file
const olm = new ae.Storage.Olm.OlmStorage.fromFile("test.olm");

// Get the "Inbox" folder
const folder = olm.getFolder("Inbox", true);

// Loop through messages in the folder
const messages = folder.enumerateMessages();
for (let messageInfo of messages) {
    if (messageInfo.date.toDateString() === new Date().toDateString()) {
        // Extract today's messages from Inbox
        const msg = olm.extractMapiMessage(messageInfo);

        // You can now work with `msg`, which represents the MapiMessage object
        console.log(`Subject: ${msg.subject}`);
    }
}
 

The code gives developers quick access to email data, including metadata such as sender information, date, and subject line. Similarly, other OLM components such as calendar items, contacts, and notes are easily accessible using corresponding methods within the API.

Convert OLM to PST

Since it is not possible to open an Outlook for Mac file in Outlook for Windows, you may be interested in mailbox migration from Outlook for Mac to Outlook for Windows. For this purpose, Aspose.Email provides functionality to convert OLM files to Outlook PST file format. The PersonalStorage.create method creates a new PST file. The addToPst() function will transfer folders and messages while preserving the hierarchy.

Convert OLM to PST in Node.js via .NET

const aspose = require('@aspose/email');

// Load the source OLM file
const olm = ae.Storage.Olm.OlmStorage.fromFile("test.olm");

// Create a new PST file in Unicode format
const pst = ae.Storage.Pst.PersonalStorage.create("my.pst", ae.Storage.Pst.FileFormatVersion.Unicode);

// Function to recursively add OLM folders and messages to the PST
function addToPst(pstFolder, olmFolder) {
    // Create a corresponding subfolder in PST
    const subFolder = pstFolder.addSubFolder(olmFolder.name);

    // Iterate through each message in the OLM folder and add it to the PST subfolder
    const messages = olmFolder.enumerateMessages();
    for (let messageInfo of messages) {
        const msg = olm.extractMapiMessage(messageInfo);
        subFolder.addMessage(msg);
    }

    // Recursively process subfolders
    const subFolders = olmFolder.enumerateFolders();
    for (let subOlmFolder of subFolders) {
        addToPst(subFolder, subOlmFolder);
    }
}

// Process each folder in the OLM file and add it to the root of the PST
const olmFolders = olm.folderHierarchy;
for (let olmFolder of olmFolders) {
    addToPst(pst.rootFolder, olmFolder);
}

Install Aspose.Email for Node.js via .NET

Aspose.Email for Node.js via .NET offers a feature-rich, optimized solution for reading, parsing, and extracting message content with extensive compatibility and consistent performance, making it a preferred choice for both simple and advanced email processing tasks.

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.

To start using Aspose.Email in your Node.js projects, install it via npm:

 

Command


npm install @aspose/email
 

Once installed, you’re ready to start leveraging its powerful capabilities to work with OLM files and other email formats.

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.

Reading Other Formats

Explore other file formats that the API can handle with ease.

MBOX (Electronic Mail Messages)
OST (Offline Storage Files)
PST (Outlook Personal Storage Files)
TGZ (Compressed Archive Files)