# EML, MSG & MBOX to JSON - Emails & Attachments for RAG (`that_red_bird/eml-mbox-to-json`) Actor

Turn email archives into data. Give EML, MSG or MBOX files by URL or key-value store and get one JSON row per message: headers, text, thread ID, attachment list (saved to storage) and optional RAG-ready chunks. For e-discovery, mailbox RAG and CRM migrations.

- **URL**: https://apify.com/that_red_bird/eml-mbox-to-json.md
- **Developed by:** [mohamed alaya](https://apify.com/that_red_bird) (community)
- **Categories:** Developer tools, AI, Automation
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.50 / 1,000 message 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

## EML, MSG & MBOX to JSON - Emails & Attachments for RAG

Turn email archives into clean JSON. Give it .eml, .msg or .mbox files (by URL, from a key-value store, or pasted) and get one row per message with headers, plain text, a thread ID, the attachment list (files saved to storage) and, if you want, RAG-ready chunks. For e-discovery, mailbox search with an LLM and CRM migrations.

Runs offline in the Actor, no mail server access or login is needed.

### Input examples

```json
{ "fileUrls": ["https://example.com/archive/inbox.mbox"] }
```

```json
{ "keyValueStoreId": "<store id>", "recordKeys": ["export.mbox", "invoice.eml"], "includeChunks": true, "chunkTokens": 400 }
```

```json
{ "rawContent": "From: a@example.com\nTo: b@example.com\nSubject: Hi\n\nHello", "saveAttachments": false }
```

Empty input `{}` parses a small built-in sample mailbox.

### Input guide

| Field | What it does |
|---|---|
| `fileUrls` | Direct links to .eml, .msg, .mbox files. Format is detected from content. |
| `keyValueStoreId`, `recordKeys` | Pick a store with email records; empty keys means every .eml/.msg/.mbox record. |
| `rawContent` | Paste a message or whole mbox. |
| `saveAttachments`, `maxAttachmentMb` | Store attachments in the run's key-value store (default on, 10 MB each). |
| `includeHeaders` | Add the full headers object. |
| `includeChunks`, `chunkTokens`, `overlapTokens` | Heading-aware, overlapping chunks for embeddings; each starts with subject, sender and date. |
| `maxMessages`, `maxFileMb` | Safety limits. |

### Output

| Field | Meaning |
|---|---|
| `type` | `message` or `error` |
| `source`, `messageIndex`, `format` | File, position inside it, and `eml`/`msg`/`mbox` |
| `messageId`, `inReplyTo`, `references` | Threading headers |
| `threadId`, `threadPosition`, `threadSize` | Conversation grouping (built from Message-ID, In-Reply-To and References) |
| `date`, `from`, `to`, `cc`, `bcc`, `replyTo`, `subject` | Parsed envelope fields (ISO date, name + address) |
| `text`, `textPreview`, `hasHtml`, `labels` | Body as plain text (HTML converted), Gmail labels from X-Gmail-Labels |
| `attachments[]` | `filename`, `contentType`, `size`, `inline`, `kvsKey`, `kvsUrl` |
| `headers`, `chunks[]` | All headers; RAG chunks when enabled |

Sample row (abridged):

```json
{"type":"message","source":"mail-archive.mbox","format":"mbox","messageId":"<a2@example.com>","threadId":"a2f1c3f0df4a8a73","threadPosition":3,"threadSize":3,"date":"2026-09-29T08:15:00.000Z","from":{"name":"Alice Moreau","address":"alice@example.com"},"subject":"Re: Q3 budget review","attachmentCount":1,"attachments":[{"filename":"q3-budget.txt","size":93,"kvsKey":"att-1a2b3c4d5e-q3-budget.txt"}]}
```

### Use it with

- Google Takeout or Thunderbird .mbox export -> this Actor -> vector database (use the `chunks` array).
- `website-to-rag-incremental` covers web pages; this Actor covers the mailbox side of the same RAG pipeline.

### FAQ

**Are threads reliable?** Threads follow the standard headers. Messages with stripped Message-ID/References headers cannot be linked and each become their own thread.

**Does it read PST or Outlook OST?** No, only EML, MSG and MBOX.

### Limits (honest)

- MSG support uses a pure-JavaScript reader; very old or encrypted MSG files may fail and become error rows. Tested on the platform with a sample Outlook MSG with an attachment.
- Reading a key-value store you pick needs the Actor's full-permissions mode.
- Very large mbox files are loaded into memory (default cap 100 MB per file).
- Token counts are estimated (characters / 4).

### Price

Pay per event: `message-parsed` $0.0005 per message row. Example: a 10,000-message mailbox costs $5.00. Error rows are free.

# Actor input Schema

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

Direct download links to .eml, .msg or .mbox files (one message per .eml/.msg, many per .mbox). The format is detected from the file content. Leave everything empty to run on a built-in sample mailbox.

## `keyValueStoreId` (type: `string`):

Pick a key-value store that holds .eml, .msg or .mbox records (for example uploaded in the Console). All records with those extensions are parsed unless you list the record keys below.

## `recordKeys` (type: `array`):

Only parse these record keys from the selected key-value store. Empty means every .eml, .msg and .mbox record in it.

## `rawContent` (type: `string`):

Paste the full source of one message or a whole mbox here instead of using a file. Useful for agents and quick tests.

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

Store every attachment as a record in the run's key-value store and put its download link in the message row. Turn off to list attachments (name, type, size) without saving the files.

## `maxAttachmentMb` (type: `integer`):

Attachments larger than this are listed but not saved.

## `includeHeaders` (type: `boolean`):

Add a headers object with every header of the message (Received, Authentication-Results, X-headers, ...). Turn off for smaller rows.

## `includeChunks` (type: `boolean`):

Split each message body into overlapping chunks ready for embedding. Every chunk starts with the subject, sender and date so it can be retrieved on its own.

## `chunkTokens` (type: `integer`):

Target chunk size when RAG chunks are on. Tokens are estimated as characters divided by four.

## `overlapTokens` (type: `integer`):

Tokens repeated between neighbouring chunks when RAG chunks are on.

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

Stop after this many messages in total across all files.

## `maxFileMb` (type: `integer`):

Files larger than this are skipped with an error row.

## Actor input object example

```json
{
  "fileUrls": [],
  "recordKeys": [],
  "rawContent": "",
  "saveAttachments": true,
  "maxAttachmentMb": 10,
  "includeHeaders": true,
  "includeChunks": false,
  "chunkTokens": 512,
  "overlapTokens": 50,
  "maxMessages": 5000,
  "maxFileMb": 100
}
```

# Actor output Schema

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

No description

## `downloadCsv` (type: `string`):

No description

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

No description

## `count` (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": [],
    "recordKeys": [],
    "rawContent": "",
    "saveAttachments": true,
    "maxAttachmentMb": 10,
    "includeHeaders": true,
    "includeChunks": false,
    "chunkTokens": 512,
    "overlapTokens": 50,
    "maxMessages": 5000,
    "maxFileMb": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("that_red_bird/eml-mbox-to-json").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": [],
    "recordKeys": [],
    "rawContent": "",
    "saveAttachments": True,
    "maxAttachmentMb": 10,
    "includeHeaders": True,
    "includeChunks": False,
    "chunkTokens": 512,
    "overlapTokens": 50,
    "maxMessages": 5000,
    "maxFileMb": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("that_red_bird/eml-mbox-to-json").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": [],
  "recordKeys": [],
  "rawContent": "",
  "saveAttachments": true,
  "maxAttachmentMb": 10,
  "includeHeaders": true,
  "includeChunks": false,
  "chunkTokens": 512,
  "overlapTokens": 50,
  "maxMessages": 5000,
  "maxFileMb": 100
}' |
apify call that_red_bird/eml-mbox-to-json --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,that_red_bird/eml-mbox-to-json"
        }
    }
}
```

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/WMWgk6JhHPFwq4RGf/builds/ZfYTzEcw886Zf7cEu/openapi.json
