Reading .msg files from the command line

Print the headers and body of an Outlook .msg, save its attachments and convert it to .eml from a terminal, with real output from a sample file.

By Andy Liu, who builds MsgLens ·

A browser viewer is right for one message. It is the wrong tool for a folder of 400 exported messages, a server with no screen, or a script that must read the sender of every file in a support inbox. For those jobs you want a command.

This post shows how to read .msg files from a terminal with msglens-cli, the command-line build of the parser behind this site. It also lists two other tools, and the one check you should run on any of them before you trust it with real mail.

Install, or run without installing

You need Node.js 20 or later. Then either of these works:

# run once, nothing installed
npx msglens-cli read message.msg

# or install the "msglens" command
npm install -g msglens-cli

The parser runs on your machine. It makes no network request, so it also works on a computer with no internet access once the package is installed.

Print a message

read prints the main headers, the attachment names and the body as plain text. This is the real output for our public sample file, shortened at the end:

$ msglens read sample-message.msg
From: Dana Whitfield <[email protected]>
To: Sam Okafor <[email protected]>
Date: Thu Mar 12 2026 17:24:00 GMT+0800 (Taiwan Standard Time)
Subject: Q3 supplier review - notes before Thursday
Attachments: msglens-logo.png, q3-supplier-rates.csv

------------------------------------------------------------

Hi Sam,
Thanks for pulling the Q3 numbers together. ...

The date is shown in the time zone of the computer that runs the command. The file stores it in UTC, so the same message prints a different clock time on a server in another country. Use the JSON output when the exact value matters.

Get everything as JSON

Add --json for the full parsed message. One file gives one object; several files give an array. These are the fields you will use most:

  • subject, from, to, cc: the addresses come as { name, address } pairs.
  • date: an ISO 8601 string in UTC, for example 2026-03-12T09:24:00.000Z.
  • bodyText: always filled, even when the message only had an HTML or RTF body.
  • body and bodyKind: the HTML when there is HTML.
  • bodySource: where the body came from (html, rtf or text).
  • attachments: name, type and size for each one. The bytes are left out of the JSON.
  • headers: the raw transport headers, when the message has them.

With jq you can turn a folder into a table. This prints the date, sender and subject of every message, one per line:

msglens read ./mail/*.msg --json \
  | jq -r '.[] | [.date, .from.address, .subject] | @tsv'

Save the attachments

$ msglens attachments sample-message.msg -o ./attachments
attachments/msglens-logo.png
attachments/q3-supplier-rates.csv

It never overwrites a file. When we ran the same command a second time, it saved msglens-logo (1).png and q3-supplier-rates (1).csv next to the first copies. Attachment names are reduced to a plain file name first, so a message cannot write outside the folder you gave it.

An email attached inside an email is saved as its own .msg. Run the same command on that file to go one level deeper.

Convert to .eml or text

msglens convert ./mail/*.msg --to eml -o ./eml
msglens convert ./mail/*.msg --to txt -o ./txt

A file that fails is reported, and the rest still convert. The exit code is 1 if any file failed, so a script can tell. A missing file looks like this:

$ msglens read nonexist.msg
msglens: nonexist.msg: ENOENT: no such file or directory, open 'nonexist.msg'
$ echo $?
1

For what an .eml keeps and loses compared with the original, see EML vs MSG.

Other tools

Two older tools do part of the same job:

  • extract-msg (Python, pip install extract-msg) reads .msg files and saves their parts to a folder.
  • msgconvert (Perl, the libemail-outlook-message-perl package on Debian and Ubuntu) converts a .msg to an .eml.

Whichever you use, test it on a real business message, not only on a sample. In our measurement, 17 of 20 real messages stored their formatted body only as compressed RTF. A parser that does not decode RTF returns an empty or plain body for those files. Why most Outlook messages have no HTML body explains what is in the file.

Use it from an AI assistant

msglens mcp starts a Model Context Protocol server, so an assistant such as Claude can open email files on your computer itself. For Claude Code:

claude mcp add msglens -- npx -y msglens-cli mcp

The message text was written by its sender. The server tells the assistant to treat it as data and not to follow instructions inside it.

Try it now

  1. Download the sample message.
  2. Run npx msglens-cli read sample-message.msg.
  3. Compare the output with the same file opened in the browser viewer.

Found a mistake, or something this page should cover? Email us

Open a .msg file right now

No sign-up, no upload, no software to install.

Open the free .msg viewer