# MBOX to JSON: Split Mailbox Exports into Emails (`eliai/mbox-to-json`) Actor

Turn .mbox mailbox exports (Gmail Takeout, Thunderbird, Apple Mail; .mbox or .gz) into one JSON row per email: from, to, cc, subject, date, thread ids, Gmail labels, text body, links and attachments. Streams multi-GB files. For archive migration, e-discovery and AI agents. Failed emails are free.

- **URL**: https://apify.com/eliai/mbox-to-json.md
- **Developed by:** [Broke to Built](https://apify.com/eliai) (community)
- **Categories:** Developer tools, Automation
- **Features:** 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 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

### MBOX to JSON: Split Mailbox Exports into Emails

**Give a link to an `.mbox` mailbox export. Get one clean JSON row per email: sender, recipients, subject, date, thread ids, Gmail labels, text body, links and attachments. Multi-GB mailboxes are streamed, never loaded whole.**

Works with **Gmail / Google Takeout**, **Thunderbird**, **Apple Mail**, **mailing-list archives** (Mailman, Pipermail) and anything else that writes standard mbox, plain or gzipped (`.mbox.gz`).

| You give it | You get back | You pay (Free plan) |
|---|---|---|
| `.mbox` or `.mbox.gz` file URLs | `from`, `to`, `cc`, `bcc`, `subject`, `date`, `messageId`, `inReplyTo`, `references`, `gmailThreadId`, `gmailLabels`, `text`, `links`, `attachments` | **$0.0005 per email** ($0.50 per 1,000) |

Emails that cannot be parsed, emails over your size limit, skipped or filtered emails, failed downloads and links to private or internal addresses are **never charged**.

#### Try it in one click

Press **Start** with the form empty. A built-in 3-email sample mailbox is split **for free**:

```json
{}
```

```json
{
  "ok": true,
  "emailIndex": 2,
  "subject": "Re: Invoice 1042 is ready",
  "from": [{ "name": "Ops Team", "address": "ops@example.org" }],
  "date": "2026-11-10T20:30:00.000Z",
  "inReplyTo": "<sample-1042@example.com>",
  "gmailThreadId": "1780000000000000001",
  "gmailLabels": ["Sent"],
  "text": "Thanks Ada, paid today. Receipt attached.\n",
  "attachments": [{ "filename": "receipt-1042.csv", "contentType": "text/csv", "size": 42, "inline": false }],
  "sample": true
}
```

#### Read your own mailbox

```json
{
  "mboxUrls": ["https://your-bucket.s3.amazonaws.com/takeout/All-mail-Including-Spam-and-Trash.mbox"],
  "maxEmails": 5000,
  "searchText": "invoice"
}
```

### Why use it

An `.mbox` file is thousands of emails glued together in one text file. LLMs, AI agents and spreadsheets cannot use it as is: it is too big to paste, and splitting it correctly (escaped `>From ` lines, MIME parts, encodings) is easy to get wrong. This Actor does the splitting and parsing and gives you rows you can filter, export to CSV, or feed to a model.

### Features

- **Streams any size.** The file is read as it downloads; memory stays flat. Stop early with `maxEmails` and reading stops too.
- **Pages through huge exports** with `skipEmails` + `maxEmails`.
- **Filter as you read** with `searchText` (subject, people and body). Emails left out cost nothing.
- **Gmail extras**: `X-GM-THRID` thread id and `X-Gmail-Labels` as an array.
- **Threads**: `messageId`, `inReplyTo` and `references` for rebuilding conversations.
- **Attachments**: name, MIME type, size and inline flag for every file.
- **Correct mbox handling**: mboxrd `>From ` un-escaping, LF or CRLF, gzip detected automatically.

### Who this is for

- **AI agents and RAG pipelines** indexing a mailbox export.
- **Legal, compliance and e-discovery** reviewing exported mail.
- **Researchers** working with mailing-list archives.
- **Anyone leaving Gmail** who wants their mail as a spreadsheet.

### Input

| Field | What it does |
|---|---|
| `mboxUrls` | Links to `.mbox` or `.mbox.gz` files (up to 20 per run). |
| `mboxText` | A small mailbox pasted as text. |
| `maxEmails` | Stop after this many emails are written (default 10,000). |
| `skipEmails` | Skip this many emails first (free). |
| `searchText` | Keep only emails containing this phrase. |
| `includeHtml` | Add the HTML body (default off). |
| `bodyMaxChars` | Cut long bodies to this length (default 20,000). |
| `maxMessageMb` | Skip single emails bigger than this (default 25). |
| `maxFileSizeMb` | Stop reading past this file size (default 2,048). |

### Pricing

Pay per event: **$0.0005 per email written.** The free sample, and every skipped, filtered or failed email, cost nothing. Set a max charge on the run to cap your spend.

### Privacy and safety

Your mailbox is streamed through memory for the run and kept only in your own run's dataset. Links to private networks, localhost or cloud metadata addresses are refused on every redirect.

### Related

Single emails? Use our **EML to JSON** or **Outlook MSG to JSON** Actors.

# Actor input Schema

## `mboxUrls` (type: `array`):

Public links to .mbox files, plain or gzip. The file is streamed, so very large mailboxes work. Leave empty to see a free 3-email sample.

## `mboxText` (type: `string`):

Paste a small mailbox as text instead of a link.

## `maxEmails` (type: `integer`):

Stop after this many emails are written (and charged). Reading stops too, so you never pay for more.

## `skipEmails` (type: `integer`):

Skip this many emails from the start of the file before writing (skipped emails are free). Use with Max emails to read a big mailbox in pages.

## `searchText` (type: `string`):

Optional. Keep only emails whose subject, sender, recipients or text contain this phrase (case-insensitive). Emails left out are not charged.

## `includeHtml` (type: `boolean`):

Add the HTML body to each row. Off by default to keep big exports small; the text body is always included.

## `bodyMaxChars` (type: `integer`):

Longer text or HTML bodies are cut to this length (textTruncated tells you). 0 drops bodies entirely.

## `maxMessageMb` (type: `integer`):

Bigger emails (usually huge attachments) are listed as skipped and not charged.

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

Reading stops if the file grows past this size.

## Actor input object example

```json
{
  "mboxUrls": [],
  "maxEmails": 10000,
  "skipEmails": 0,
  "includeHtml": false,
  "bodyMaxChars": 20000,
  "maxMessageMb": 25,
  "maxFileSizeMb": 2048
}
```

# Actor output Schema

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

One row per email. Export as JSON, CSV or Excel from the dataset view.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("eliai/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 = {}

# Run the Actor and wait for it to finish
run = client.actor("eliai/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 '{}' |
apify call eliai/mbox-to-json --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eliai/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/xhQpiOI5b5rTeVSqa/builds/c1x8JbFoFtcTKaYWO/openapi.json
