# Email File Parser – EML, MSG & MBOX to JSON with Attachments (`gazidev/email-file-parser`) Actor

Parse .eml, Outlook .msg and .mbox mailbox files into JSON: from/to/cc, subject, ISO date, text and HTML body, attachments (optionally saved), Message-ID thread IDs and SPF/DKIM/DMARC results. $0.50 per 1,000 emails.

- **URL**: https://apify.com/gazidev/email-file-parser.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 email parseds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Email File Parser – EML, MSG & MBOX to JSON with Attachments

Turn email files into clean JSON. Give it links to **.eml** files, **Outlook .msg** files or whole **.mbox** mailboxes (Gmail Takeout, Thunderbird, Apple Mail, mailing-list archives) and get **one row per message**: sender, recipients, subject, ISO date, plain-text and HTML body, the attachment list, Message-ID / In-Reply-To / References with a ready **thread ID**, and the **SPF / DKIM / DMARC** results the receiving server recorded.

The format is detected from the file content, not the file name. Big mailboxes are read one message at a time, so memory use stays low (tested up to a few MB locally; files up to 2 GB are accepted). **$0.50 per 1,000 emails.**

### Use cases

- **eDiscovery and compliance exports:** turn a custodian's .mbox or a folder of .msg files into a table you can filter, search and load into a database.
- **Mailbox migration and archiving:** convert Gmail Takeout or Thunderbird mailboxes to JSON/CSV/Excel with thread IDs kept.
- **Feeding AI / RAG pipelines:** clean `textBody` (or `htmlAsText`, plain text made from the HTML part) per message, with the metadata to cite it.
- **Phishing and deliverability triage:** read `spf`, `dkim`, `dmarc`, `dkimDomains` and the full `Authentication-Results` of reported emails; list attachments with SHA-256 hashes for threat-intel lookups, without opening them.
- **Invoice / order mailbox processing:** extract every PDF/XLSX attachment of a mailbox into a key-value store, with a link per file.

### Input

| Field | Default | Notes |
|---|---|---|
| `fileUrls` | a small demo .eml (a Python test file with fake addresses) | Direct links to `.eml`, `.msg` or `.mbox` files. Links that redirect are followed. |
| `uploadedFiles` + `uploadStore` | – | Upload files from your computer in the Console. Also select the store you uploaded into (the Actor runs with limited permissions). |
| `datasetId` / `datasetField` | – / `url` | Read file URLs from one of your datasets. |
| `saveAttachments` | `false` | Save attachments into this run's key-value store and add `kvKey` + `url` to each attachment. Charged per saved file. |
| `saveInlineImages` | `false` | Also save inline (cid:) images such as logos and signatures. |
| `maxAttachmentSizeMb` | 25 | Bigger attachments are listed but not saved. |
| `includeHtmlBody` | `true` | Off: only `textBody` and `htmlAsText`. |
| `includeRawHeaders` | `false` | Add every header (Received chain, X- headers) as a `headers` list. |
| `maxBodyChars` | 100,000 | Body fields are cut to this length (`bodyTruncated: true`). 0 = no limit. |
| `maxMessages` | 0 (no limit) | Stop after N messages, e.g. to preview a big mailbox. |
| `maxFileSizeMb` | 200 | Bigger files are refused (free). Up to 2,000. |

```json
{
  "fileUrls": ["https://example.com/exports/inbox.mbox", "https://example.com/mail/quote-request.msg"],
  "saveAttachments": true,
  "includeHtmlBody": false
}
```

### Output (one row per message)

```json
{
  "source": "https://raw.githubusercontent.com/python/cpython/main/Lib/test/test_email/data/msg_07.txt",
  "fileName": "msg_07.txt",
  "format": "eml",
  "messageIndex": 1,
  "status": "ok",
  "subject": "Here is your dingus fish",
  "normalizedSubject": "Here is your dingus fish",
  "date": "2001-04-20T19:35:02-04:00",
  "from": "Barry <barry@digicool.com>",
  "fromName": "Barry",
  "fromAddress": "barry@digicool.com",
  "to": ["Dingus Lovers <cravindogs@cravindogs.com>"],
  "cc": [], "bcc": [], "replyTo": [],
  "recipientAddresses": ["cravindogs@cravindogs.com"],
  "messageId": null, "inReplyTo": null, "references": [], "threadId": null,
  "textBody": "Hi there,\n\nThis is the dingus fish.",
  "htmlBody": "", "htmlAsText": "", "bodyTruncated": false,
  "attachments": [{
    "name": "dingusfish.gif", "mimeType": "image/gif", "size": 3512,
    "sha256": "354288075c6cd6c6a99180ef60b99f599b4e3d6c28bd67c29adc736079e52a84",
    "contentId": null, "inline": false,
    "kvKey": "att-001-00001-01-dingusfish.gif",
    "url": "https://api.apify.com/v2/key-value-stores/<store>/records/att-001-00001-01-dingusfish.gif"
  }],
  "attachmentCount": 1, "hasAttachments": true,
  "authenticationResults": [], "dkimDomains": [], "spf": null, "dkim": null, "dmarc": null
}
```

- **Outlook .msg rows** also have `messageClass` (e.g. `IPM.Note`) and `conversationIndex`. Without RFC thread headers, `threadId` is `conv:<conversation index>`, so replies in one Outlook conversation share a thread ID.
- **`threadId`** is the first `References` ID, else `In-Reply-To`, else the message's own `Message-ID`. Group by it to rebuild conversations.
- **Embedded emails** (forwarded-as-attachment, bounces, digests, .msg inside .msg) are listed as attachments with an `embeddedMessage` summary (subject, from, date).
- **Error rows** (`status: "error"`, `errorCode`, `error`) are free: bad link, HTTP error, file too large, not an email file, private-network address.
- The run summary (messages, attachments, errors, formats, whether the max charge stopped the run) is in the `OUTPUT` record of the key-value store.

### Attachments are never opened

Attachments are read only to count their size and compute a SHA-256 hash. When `saveAttachments` is on, each file is stored **as `application/octet-stream`**, whatever its declared type, so a browser downloads it instead of showing or running it. Nothing inside an attachment is executed, unpacked or rendered. Be careful with attachments from unknown senders when you open them on your own computer.

### Privacy

Mailboxes contain personal data. The files you give are downloaded into the run's temporary disk, parsed and deleted when the run ends. The results and saved attachments go only to **your own** run storage (dataset and key-value store) in your Apify account; we do not keep a copy. Apify deletes unnamed run storage after your plan's retention period. Process only mail you are allowed to process.

### Limits (please read)

- **Supported:** RFC 5322 `.eml` (any MIME structure, RFC 2047 encoded headers, any charset Python knows), `.mbox` (mboxo/mboxrd "From " separated, incl. Gmail Takeout), Outlook `.msg` (OLE2/CFB, Unicode and ANSI).
- **Not supported:** `.pst`/`.ost` Outlook data files, Maildir folders, `.emlx`, TNEF `winmail.dat` contents (listed as an attachment, not unpacked), S/MIME or PGP decryption, ZIP archives of mail (unzip them first, e.g. with our Archive Extractor).
- **Outlook RTF-only bodies** are converted to plain text with a simple RTF reader: formatting and tables are lost, and `htmlBody` is empty. Most Outlook messages also carry an HTML or text body, which is used first.
- **Outlook .msg recipients** stored only as Exchange addresses (`/O=EXCHANGELABS/...`) without an SMTP address appear by display name only.
- `.msg` files are read whole into memory; keep single .msg files under about 200 MB at 256 MB memory. MBOX and EML size is limited only by `maxFileSizeMb`.
- An Apify dataset row is limited to about 9 MB, which is why bodies are cut at `maxBodyChars` (100,000 characters each by default).
- Links must be **direct file links** that a server returns without logging in. Private and internal network addresses (localhost, 10.x, 192.168.x, cloud metadata) are refused.

### Pricing

Pay per event:

| Event | Price | When |
|---|---|---|
| Email parsed | **$0.0005** ($0.50 per 1,000) | each message returned with `status: "ok"` |
| Attachment saved | $0.0005 | each attachment stored in the key-value store (only with `saveAttachments`) |
| Actor start | $0.00005 | once per run |

Error rows are free. Listing attachments (name, type, size, SHA-256) without saving them is free. The run stops cleanly when your maximum total charge is reached; `OUTPUT` then has `stoppedAtMaxCharge: true`.

| Actor | Formats | Price |
|---|---|---|
| **This Actor** | EML + MSG + MBOX in one run, attachments, threads, SPF/DKIM/DMARC | $0.50 / 1,000 emails |
| Single-format MSG-to-JSON and MBOX-to-JSON Actors in the Store | one format each | see their pricing pages |

### How this differs from our other listings

- [Document to Markdown](https://apify.com/gazidev/document-to-markdown) converts PDF/DOCX/HTML documents; it does not read mail files. Use it on attachments you saved here.
- [Archive Extractor](https://apify.com/gazidev/archive-extractor) unzips ZIP/TAR/7z files; use it first when your mailbox export is zipped.
- [Email Auth Checker](https://apify.com/gazidev/email-auth-checker) checks a **domain's** SPF/DKIM/DMARC DNS records; this Actor reads the **per-message** results recorded in received emails.
- [Email Blacklist Checker](https://apify.com/gazidev/email-blacklist-checker) and [Email Syntax & MX Validator](https://apify.com/gazidev/email-syntax-mx-validator) check addresses and mail servers; pass them the `fromAddress` / `recipientAddresses` from this Actor.

### Use with AI agents (Apify MCP)

Through the [Apify MCP server](https://mcp.apify.com), an AI agent can call `gazidev/email-file-parser` with `fileUrls` and get structured messages back, e.g. "read this .msg and tell me who was copied and what was attached", or "summarise this mailing-list archive by thread". Set `includeHtmlBody: false` to keep the agent's context small.

### FAQ

**Does it work with Gmail Takeout?** Yes. Takeout gives `.mbox` files; host the file somewhere with a direct link or upload it in the Console.

**Can it read a .pst file?** No, only `.msg`, `.eml` and `.mbox`. Export the folder from Outlook as .msg files, or convert the PST to MBOX first.

**Are attachments scanned for viruses?** No. They are not opened at all. Use the SHA-256 in the output to look them up in your threat-intel tool.

**Why is `messageId` null for some emails?** The file has no `Message-ID` header (common in drafts, test files and some Outlook items). Outlook items still get a `conv:` thread ID.

**Licence of libraries:** Python standard library (`email`, `mailbox`), `olefile` (BSD-2) and `compressed-rtf` (MIT). No GPL code.

# Actor input Schema

## `fileUrls` (type: `array`):

Direct links to .eml, Outlook .msg or .mbox files (Gmail Takeout, Thunderbird, Apple Mail exports). The format is detected from the file content. Private-network addresses are refused.

## `uploadedFiles` (type: `array`):

This Actor runs with limited permissions, so ALSO select the store you uploaded into in 'Key-value store with your uploads'. When you upload files, the pre-filled demo file is ignored.

## `uploadStore` (type: `string`):

Grants this run read access to that store only. If 'uploadedFiles' points into it, only those files are parsed; otherwise every file in the store is (up to 1,000, JSON records skipped).

## `datasetId` (type: `string`):

Every item's URL field (below) is parsed.

## `datasetField` (type: `string`):

Field name in that dataset (a string, a list of strings or {url} objects).

## `saveAttachments` (type: `boolean`):

Store each attachment in this run's key-value store (charged per saved file) and add its key and link to the row. Files are stored as application/octet-stream and are never opened or executed. Off: you still get name, type, size and SHA-256 of every attachment.

## `saveInlineImages` (type: `boolean`):

Inline images are usually logos and signature graphics, so they are skipped by default.

## `maxAttachmentSizeMb` (type: `integer`):

Larger attachments are listed but not saved.

## `includeHtmlBody` (type: `boolean`):

Off: only textBody and htmlAsText (plain text made from the HTML) are returned, which keeps rows small.

## `includeRawHeaders` (type: `boolean`):

Add a 'headers' list with every header (name, value), e.g. Received chains and X- headers.

## `maxBodyChars` (type: `integer`):

textBody, htmlBody and htmlAsText are cut to this length (bodyTruncated: true). 0 = no limit.

## `maxMessages` (type: `integer`):

Stop after this many parsed messages in total (useful to preview a big mailbox). 0 = no limit.

## `maxFileSizeMb` (type: `integer`):

Larger files are refused (free). For big mailboxes, raise this and the run memory is not affected: messages are read one at a time.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/python/cpython/main/Lib/test/test_email/data/msg_02.txt"
  ],
  "datasetField": "url",
  "saveAttachments": false,
  "saveInlineImages": false,
  "maxAttachmentSizeMb": 25,
  "includeHtmlBody": true,
  "includeRawHeaders": false,
  "maxBodyChars": 100000,
  "maxMessages": 0,
  "maxFileSizeMb": 200
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `threads` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `attachments` (type: `string`):

No description

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "fileUrls": [
        "https://raw.githubusercontent.com/python/cpython/main/Lib/test/test_email/data/msg_02.txt"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/email-file-parser").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "fileUrls": ["https://raw.githubusercontent.com/python/cpython/main/Lib/test/test_email/data/msg_02.txt"] }

# Run the Actor and wait for it to finish
run = client.actor("gazidev/email-file-parser").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "fileUrls": [
    "https://raw.githubusercontent.com/python/cpython/main/Lib/test/test_email/data/msg_02.txt"
  ]
}' |
apify call gazidev/email-file-parser --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gazidev/email-file-parser"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/RWg2UVtKItBFqzzP5/builds/ijvAZbck64R6buW81/openapi.json
