npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

outlook-email-parser

v2.0.0

Published

Parse Microsoft Outlook email files (MSG, EML, PST, OFT) with full support for attachments, embedded images, and various encodings

Downloads

95

Readme

outlook-email-parser

Parse Microsoft Outlook email files (MSG, EML, OFT) with full support for attachments, embedded images, and various character encodings.

Features

  • 📧 Parse MSG files (Microsoft Outlook Message format)
  • 📨 Parse EML files (Standard email format)
  • 📎 Extract attachments with content
  • 🖼️ Support for embedded images (CID references)
  • 🌍 Multi-language support (Vietnamese, Chinese, Japanese, etc.)
  • 📝 Extract both HTML and plain text content
  • 🔧 Zero external binary dependencies

Installation

npm install outlook-email-parser
# or
yarn add outlook-email-parser
# or
pnpm add outlook-email-parser

Usage

Basic Usage

import { parseEmail } from 'outlook-email-parser';
import { readFileSync } from 'fs';

// Parse any supported email file
const buffer = readFileSync('email.msg');
const result = await parseEmail(buffer, 'email.msg');

console.log(result.data.subject);
console.log(result.data.from);
console.log(result.data.to);
console.log(result.data.htmlContent);
console.log(result.data.attachments);

Parse MSG Files

import { parseMsgBuffer } from 'outlook-email-parser';
import { readFileSync } from 'fs';

const buffer = readFileSync('message.msg');
const email = parseMsgBuffer(buffer);

console.log(email.subject);
console.log(email.from.name, email.from.email);
console.log(email.textContent);

Parse EML Files

import { parseEmlBuffer } from 'outlook-email-parser';
import { readFileSync } from 'fs';

const buffer = readFileSync('message.eml');
const email = await parseEmlBuffer(buffer);

console.log(email.subject);
console.log(email.htmlContent);

Working with Attachments

import { parseEmail } from 'outlook-email-parser';
import { readFileSync, writeFileSync } from 'fs';

const buffer = readFileSync('email.msg');
const result = await parseEmail(buffer, 'email.msg');

for (const attachment of result.data.attachments) {
  console.log(`Attachment: ${attachment.filename} (${attachment.size} bytes)`);
  
  // Save attachment to disk
  if (attachment.content) {
    const data = Buffer.from(attachment.content, 'base64');
    writeFileSync(attachment.filename, data);
  }
}

Parser Options

import { parseEmail } from 'outlook-email-parser';

const result = await parseEmail(buffer, 'email.msg', {
  // Include attachment content (base64). Default: true
  includeAttachmentContent: true,
  
  // Maximum attachment size to include content (bytes). Default: 10MB
  maxAttachmentSize: 10 * 1024 * 1024,
});

API Reference

parseEmail(buffer, fileName, options?)

Parse an email file with automatic format detection.

  • buffer: Buffer - The file content
  • fileName: string - The filename (used for format detection)
  • options: ParserOptions - Optional parser configuration

Returns: Promise<ParseResult>

parseMsgBuffer(buffer, options?)

Parse an MSG file buffer.

  • buffer: Buffer - The MSG file content
  • options: ParserOptions - Optional parser configuration

Returns: ParsedEmail

parseEmlBuffer(buffer, options?)

Parse an EML file buffer.

  • buffer: Buffer - The EML file content
  • options: ParserOptions - Optional parser configuration

Returns: Promise<ParsedEmail>

isValidMsgFile(buffer)

Check if a buffer is a valid MSG file.

Returns: boolean

isValidEmlFile(buffer)

Check if a buffer looks like a valid EML file.

Returns: boolean

Types

interface ParsedEmail {
  subject: string;
  from: EmailAddress;
  to?: string;
  cc?: string;
  bcc?: string;
  replyTo?: string;
  sentDate?: string;
  receivedDate?: string;
  priority?: number;
  importance?: number;
  textContent?: string;
  htmlContent?: string;
  attachments: EmailAttachment[];
}

interface EmailAddress {
  name?: string;
  email?: string;
}

interface EmailAttachment {
  filename: string;
  size: number;
  contentId?: string;
  content?: string; // base64 encoded
  mimeType?: string;
}

interface ParserOptions {
  includeAttachmentContent?: boolean;
  maxAttachmentSize?: number;
}

Supported Formats

| Format | Extension | Description | |--------|-----------|-------------| | MSG | .msg | Microsoft Outlook Message | | OFT | .oft | Microsoft Outlook Template | | EML | .eml | Standard email format (RFC 822) |

Character Encoding Support

The parser automatically detects and handles various character encodings:

  • UTF-8
  • UTF-16LE/BE
  • Windows-1252 (Western European)
  • Windows-1258 (Vietnamese)
  • ISO-8859-1 (Latin-1)
  • And many more via iconv-lite

License

MIT