# IMAP Mail Intelligence – iCloud (`badr_xba/imap-mail-intelligence`) Actor

Read your own mailbox READ-ONLY with an app-specific password (iCloud, Yahoo, Zoho, GMX, Fastmail, any IMAP) or import MBOX / EML: search, export, attachments, stats, duplicates, threads, phishing signs, AI summary with your key. Free demo.

- **URL**: https://apify.com/badr_xba/imap-mail-intelligence.md
- **Developed by:** [Badr Bouargan](https://apify.com/badr_xba) (community)
- **Categories:** Automation, AI
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.40 / 1,000 e-mail reads

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## IMAP Mail Intelligence – iCloud, Yahoo & Any IMAP (Read-Only)

Turn **your own mailbox** into clean, searchable data – **read-only**. Connect iCloud Mail, Yahoo, AOL, Zoho, GMX,
Fastmail, OVHcloud, Gmail (personal) or any IMAP server with an **app-specific password**, or import an **MBOX / EML /
ZIP** export. Get one row per e-mail with its text, attachments, category, conversation, duplicate check and phishing
warning signs, plus a mailbox report – and, if you want, an **AI summary with your own OpenAI, Anthropic or Gemini key**.

**Try it first for free:** run it with an empty input and you get a **demo on a fictional mailbox** (14 invented
e-mails, clearly marked `demo: true`) in a few seconds – no account, nothing charged.

> **Not affiliated with Apple, Google, Microsoft, Yahoo, AOL, Zoho, GMX, Fastmail or OVHcloud.** Provider names are
> used only to describe compatibility. No logo of these companies is used.

![Your mailbox, read-only, as clean data](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-01-cover.png)

### Why it is safe to use

- **Read-only by design.** Folders are opened with IMAP `EXAMINE` (read-only) and messages are fetched with
  `BODY.PEEK`, so **nothing is marked as read**. A built-in guard refuses every command that could change your mailbox
  (`STORE`, `COPY`, `MOVE`, `EXPUNGE`, `APPEND`, `DELETE`…) **before** it is sent. The Actor never sends, deletes,
  moves, flags or forwards an e-mail.
- **App-specific password only – never your main password.** You create it at your provider and can revoke it in one
  click when you are done.
- **Secrets stay secret.** The app-specific password and your AI key go into **secret input fields** (stored encrypted
  by Apify). They are removed from every log line, result row, file and error message.
- **E-mails are treated as untrusted content.** HTML is never rendered, links are never opened, attachments are never
  opened or run. Your data stays in your own Apify storage; nothing is sent anywhere else (except to your own AI
  provider, only if you turn AI on).

### What you get

| Feature | What it does | Charged? |
|---|---|---|
| Read & search | Folders, date range, sender, recipient, subject, keywords, unread only, with attachments only (server-side IMAP search when possible, then checked locally) | per e-mail read |
| Export | Dataset (JSON, CSV, Excel, API) + a spreadsheet-safe `EMAILS_CSV` file | included |
| Attachments | Name, type, size, SHA-256 for every file; optional saving to your key-value store with per-file and per-run size limits | file saved |
| Mailbox report | Top senders and domains, e-mails per month / weekday / hour, categories, attachments, duplicates | once per run |
| Duplicates | Same Message-ID or same content in several folders (reported only, never deleted) | free |
| Conversations | Threads from `References` / `In-Reply-To`, then subject + shared participant | free |
| Phishing warning signs | Display name vs address, Reply-To mismatch, link text vs real link, links to IP addresses, risky / double extensions (`invoice.pdf.exe`), SPF / DKIM / DMARC fail. **Indicators only, never a verdict** | free |
| Category (rules) | Business, Personal, Invoices, Orders, Support, Marketing, Important, Other | free |
| AI summary + category | With **your own** OpenAI / Anthropic / Gemini key (optional, off by default) | per e-mail analysed |
| Demo mode | Fictional sample mailbox, no account | never |

![Works with the mailbox you already have](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-02-providers-and-import.png)

### Supported providers

| Provider | Server (filled in for you) | What you need |
|---|---|---|
| iCloud Mail | `imap.mail.me.com:993` (SSL) | Two-factor authentication + an app-specific password from account.apple.com |
| Yahoo Mail / AOL Mail | `imap.mail.yahoo.com` / `imap.aol.com` :993 | An app password from the account security page |
| Zoho Mail | `imap.zoho.com` or `imap.zoho.eu` :993 | IMAP enabled; app-specific password if 2FA is on |
| GMX | `imap.gmx.com` or `imap.gmx.net` :993 | IMAP enabled in GMX settings |
| Fastmail | `imap.fastmail.com:993` | An app password with IMAP access |
| OVHcloud (MX Plan) | `ssl0.ovh.net:993` | Your mailbox password for that address |
| Gmail | `imap.gmail.com:993` | **Requires 2-Step Verification** and a Google app password. **Does not work** for Google Workspace accounts whose administrator blocks app passwords, nor for accounts with Advanced Protection (Google also says app passwords are not recommended) |
| Any other IMAP server | your server, port 993 (SSL) or 143 (STARTTLS) | Credentials for that mailbox |
| **Outlook.com / Hotmail / Live** | – | **Not supported:** Microsoft no longer accepts passwords or app passwords over IMAP (modern sign-in required since September 2024) |

Unencrypted IMAP is never used.

#### iCloud in 4 steps

1. Make sure two-factor authentication is on for your Apple Account.
2. Go to **account.apple.com → Sign-In and Security → App-Specific Passwords** and create one (name it for example
   "Apify mail").
3. In this Actor choose **iCloud Mail**, type your iCloud address, and paste the app-specific password into the
   **secret** field "App-specific password".
4. When you no longer need it, revoke it at the same place. (Changing your Apple Account password also revokes all
   app-specific passwords.)

### Input examples

Demo (no account):

```json
{}
```

Last month's invoices from iCloud, read-only:

```json
{
  "provider": "icloud",
  "emailAddress": "you@icloud.example",
  "appPassword": "<typed in the secret field>",
  "folders": ["INBOX", "Archive"],
  "dateFrom": "2026-10-01",
  "keywords": ["invoice", "facture"],
  "downloadAttachments": true,
  "maxMessages": 200
}
```

Import an Apple Mail export (Mailbox → Export Mailbox, then zip the `.mbox` folder):

```json
{ "importFileUrl": "https://files.example.com/my-export.zip" }
```

or a record of your own Apify key-value store: `"importKeyValueStoreRecord": "my-store/EXPORT"`.

![One clean row per e-mail](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-03-email-rows.png)

### Output

One dataset row per e-mail (`type: "email"`), for example:

```json
{
  "type": "email",
  "folder": "INBOX",
  "date": "2026-11-02T08:15:00Z",
  "from": {"name": "Northwind Supplies Billing", "email": "billing@northwind-supplies.example"},
  "subject": "Invoice INV-2026-1042 for October",
  "snippet": "Hello, Please find attached invoice INV-2026-1042 (amount due: EUR 1,240.00...",
  "attachments": [{"safeFilename": "invoice-INV-2026-1042.pdf", "size": 95, "sha256": "…", "riskyExtension": false}],
  "category": "Invoices",
  "phishingRiskLevel": "none",
  "threadKey": "…",
  "duplicateOf": null,
  "isRead": false,
  "demo": true
}
```

Other rows: `attachment`, `ai-analysis`, `thread`, `duplicate-group`, `mailbox-report`. Ready-made views: **E-mails,
Phishing indicators, Attachments, AI summaries, Conversations and duplicates**. Files in the key-value store:
`MAILBOX_REPORT`, `EMAILS_CSV`, `FOLDERS`, `RUN_SUMMARY`, `FAILED_INPUTS`, and saved attachments (`att-…`).

![Phishing warning signs, with the evidence](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-04-phishing-indicators.png)

### Optional AI – with your own key

Choose OpenAI, Anthropic or Gemini and paste **your** API key in the secret field. Each analysed e-mail gets a short
summary, a category, key points, action items and an injection flag. The AI cost is billed by your AI provider.

E-mail content can contain hidden instructions ("ignore previous instructions…"). This Actor is built so that they
cannot do anything:

- the e-mail is sent as **data** inside a clearly delimited block, after removing hidden HTML text and invisible
  characters; addresses and phone numbers are masked by default;
- the AI has **no tools** – it can only answer with a small JSON object, which is **checked strictly** (any extra
  field, wrong value or free text is rejected and the rules category is kept);
- the answer is only stored as text in your results: it never triggers an action, never changes billing or the
  phishing signs; and the Actor itself is read-only;
- e-mails that look like injection attempts are flagged (`aiPossiblePromptInjection`).

There is no shared or managed AI key: without your key, no AI call is made.

![AI summary with your own key](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-05-ai-your-key.png)

### Pricing

Pay per event – the current prices are on the **Pricing tab**. There is **no start fee**.

- **Charged:** each unique e-mail read, each attachment file saved, each e-mail analysed by AI (your key), one
  mailbox report per run.
- **Never charged:** demo e-mails, duplicates, conversations, duplicate groups, phishing signs, rules categories,
  failed sign-ins and other failed inputs.
- Your **Maximum cost per run** is respected: the run stops cleanly and keeps every row already delivered.

### When something goes wrong

The run still ends **SUCCEEDED** with a clear status message, and `FAILED_INPUTS` lists each problem with a stable
code: `AUTH_MISSING`, `AUTH_FAILED`, `SERVER_UNREACHABLE`, `TLS_ERROR`, `TIMEOUT`, `FOLDER_NOT_FOUND` (with the list of
your folders), `PROVIDER_NOT_SUPPORTED`, `IMPORT_TOO_LARGE`, `AI_KEY_INVALID`… Turn on **failRunOnError** if you
prefer a FAILED run (for scheduled monitoring). The run also stops cleanly before its timeout.

### How long does it take?

The demo takes a few seconds. A real mailbox depends on your provider's server and the size of the e-mails; start
with the default 50 e-mails, then raise **Maximum e-mails**. Default memory: 256 MB.

### Limits and honest notes

- Only mailboxes you own or are authorised to read. Use it in line with your provider's terms and the privacy rights of
  the people in your e-mails.
- Statistics cover the e-mails read in the run (after your filters and limits), not your whole mailbox.
- Phishing signs are heuristics: a legitimate newsletter can show some of them, and a phishing e-mail can show none.
  They are never a malware or phishing verdict; no file is scanned.
- The "registrable domain" check uses a short list of common two-level suffixes (co.uk, com.au…), not the full Public
  Suffix List.
- Very large e-mails (above **Maximum e-mail size**) are read with their headers only.
- IMAP and MBOX/EML only for now. Contacts, calendars and full backups are not included.

![Safe to try: free demo, then your mailbox](https://api.apify.com/v2/key-value-stores/R1P4OnWyoV0LnGBin/records/imapmail-06-safe-to-try.png)

### FAQ

**Will my e-mails be marked as read?** No. The Actor uses `BODY.PEEK` and read-only folders; `isRead` shows the state
on the server, unchanged.

**Can it delete or send e-mails?** No. There is no code for it, and a guard blocks every write command before it
reaches the server.

**Where are my e-mails stored?** Only in the dataset and key-value store of your own run on Apify. Set a data
retention period in your Apify settings if you want them deleted automatically.

**How do I remove the access?** Revoke the app-specific password at your provider, and clear the secret fields from
saved inputs or tasks on Apify.

Not affiliated with Apple, Google, Microsoft, Yahoo, AOL, Zoho, GMX, Fastmail or OVHcloud.

# Actor input Schema

## `source` (type: `string`):

auto = demo when no account and no file is given, IMAP when an e-mail address or password is given, file import when a file is given. demo = fictional sample mailbox (no account needed, nothing charged).

## `provider` (type: `string`):

Server settings are filled in for you. iCloud: imap.mail.me.com:993 (SSL). Outlook.com / Hotmail no longer accept app passwords over IMAP (Microsoft requires modern sign-in): not supported here. Gmail: needs 2-Step Verification and a Google app password; it does NOT work for Google Workspace accounts whose administrator blocks app passwords, nor for accounts with Advanced Protection. Choose 'Other IMAP server' to type the server yourself.

## `emailAddress` (type: `string`):

The mailbox to read (your own, or one you are authorised to read). Used as the IMAP user name unless you fill in 'IMAP user name'.

## `appPassword` (type: `string`):

NEVER your main password. Create an app-specific password at your provider (iCloud: account.apple.com > Sign-In and Security > App-Specific Passwords; two-factor authentication required) and revoke it when you no longer need it. Stored encrypted by Apify as a secret input; never logged or written to the results.

## `imapUsername` (type: `string`):

Only when the server expects another user name than the e-mail address (for example the part before @ on some iCloud accounts).

## `imapHost` (type: `string`):

Server name, for example imap.example.com. Overrides the provider preset when filled in.

## `imapPort` (type: `integer`):

993 for SSL/TLS (recommended), 143 for STARTTLS.

## `imapSecurity` (type: `string`):

ssl = TLS from the start (port 993); starttls = upgrade to TLS (port 143). Unencrypted IMAP is never used.

## `folders` (type: `array`):

Folders to read (default: INBOX for IMAP, every folder of an imported file or of the demo). Names or aliases: INBOX, Sent, Drafts, Junk, Trash, Archive. A folder that does not exist is reported in FAILED_INPUTS with the list of available folders.

## `dateFrom` (type: `string`):

Only e-mails sent on or after this day (YYYY-MM-DD).

## `dateTo` (type: `string`):

Only e-mails sent on or before this day (YYYY-MM-DD).

## `fromContains` (type: `array`):

Keep e-mails whose sender name or address contains any of these texts (for example a domain).

## `toContains` (type: `array`):

Keep e-mails whose To or Cc contains any of these texts.

## `subjectContains` (type: `array`):

Keep e-mails whose subject contains any of these texts.

## `keywords` (type: `array`):

Keep e-mails whose subject or text contains any of these words. Searched on the server first when possible, then checked locally.

## `unreadOnly` (type: `boolean`):

Only e-mails not yet read. They stay unread: this Actor never marks anything as read.

## `hasAttachments` (type: `boolean`):

Only e-mails that have at least one attached file.

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

Maximum number of e-mails read in this run (newest first).

## `maxMessagesPerFolder` (type: `integer`):

Optional cap per folder (empty = only the global maximum).

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

Bigger e-mails are read with their headers only (bodyTruncated: true).

## `connectTimeoutSecs` (type: `integer`):

How long to wait for the mail server before reporting SERVER_UNREACHABLE or TIMEOUT.

## `services` (type: `array`):

Free analyses added to the results: stats = mailbox report; duplicates = same e-mail in several folders; threads = conversations; phishing = warning signs (indicators, never a verdict); classify = category by rules; attachments = one row per attachment (metadata).

## `includeBody` (type: `boolean`):

Add the plain text of each e-mail (bodyText). Turn off to keep only headers, snippet and analyses.

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

Longer texts are cut (bodyTruncated: true).

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

Add the raw HTML (bodyHtml). It is never rendered or executed by the Actor.

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

Add a short list of headers (Reply-To, Return-Path, Authentication-Results, List-Unsubscribe, priority...).

## `exportCsv` (type: `boolean`):

Save the e-mail list as EMAILS_CSV in the key-value store (one line per e-mail, spreadsheet-safe).

## `downloadAttachments` (type: `boolean`):

Save attached files to the run's key-value store (never opened or executed). Risky types (.exe, .js, .html, macros...) are never saved: metadata only.

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

Bigger files are listed but not saved (tooLarge).

## `maxTotalAttachmentsMb` (type: `integer`):

When reached, other files are listed but not saved (runCapReached).

## `importFileUrl` (type: `string`):

Public or signed https link to an MBOX, EML or ZIP export (for example Apple Mail > Mailbox > Export Mailbox, zipped). A signed link works like a password, so it is stored encrypted and never written to logs or results. The Actor never connects to your computer.

## `importKeyValueStoreRecord` (type: `string`):

storeIdOrName/KEY of a record you uploaded to your own Apify key-value store (MBOX, EML or ZIP).

## `maxImportMb` (type: `integer`):

Bigger files are refused (IMPORT_TOO_LARGE).

## `aiProvider` (type: `string`):

Optional. Uses YOUR OpenAI, Anthropic or Gemini key: the AI cost is billed by your provider. E-mail text is sent as untrusted data; the AI has no tools and can only return a summary and a category.

## `aiApiKey` (type: `string`):

Your own API key for the chosen AI provider. Stored as a secret input; never logged or written to the results.

## `aiModel` (type: `string`):

Leave empty for a low-cost default model of the chosen provider.

## `aiLanguage` (type: `string`):

Language of the AI summaries, for example English or French.

## `maxAiEmails` (type: `integer`):

Cost guard for your AI account.

## `redactBeforeAi` (type: `boolean`):

E-mail addresses and phone numbers in the text are replaced by \[redacted] before sending to your AI provider.

## `failRunOnError` (type: `boolean`):

Off (default): the run ends SUCCEEDED with a clear message and FAILED_INPUTS. On: missing or refused credentials, unreachable server or unreadable file end the run as FAILED (useful for scheduled monitoring).

## Actor input object example

```json
{
  "source": "demo",
  "provider": "icloud",
  "imapPort": 993,
  "imapSecurity": "ssl",
  "unreadOnly": false,
  "hasAttachments": false,
  "maxMessages": 50,
  "maxMessageMb": 25,
  "connectTimeoutSecs": 30,
  "services": [
    "stats",
    "duplicates",
    "threads",
    "phishing",
    "classify"
  ],
  "includeBody": true,
  "bodyMaxChars": 20000,
  "includeHtml": false,
  "includeHeaders": true,
  "exportCsv": true,
  "downloadAttachments": false,
  "maxAttachmentMb": 10,
  "maxTotalAttachmentsMb": 100,
  "maxImportMb": 100,
  "aiProvider": "none",
  "aiLanguage": "English",
  "maxAiEmails": 25,
  "redactBeforeAi": true,
  "failRunOnError": false
}
```

# Actor output Schema

## `emails` (type: `string`):

Date, folder, sender, subject, snippet, category, phishing signs, attachments, read state.

## `security` (type: `string`):

Warning signs with their evidence (indicators only, never a verdict).

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

File name, type, size, SHA-256, risky type, saved file key.

## `ai` (type: `string`):

Summary, AI category, action items, injection attempts.

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

Conversation groups and duplicate groups (nothing is deleted).

## `allFields` (type: `string`):

Every field of every row (JSON, CSV, Excel export).

## `mailboxReport` (type: `string`):

Top senders and domains, e-mails per month / weekday / hour, categories, attachments, duplicates.

## `csv` (type: `string`):

One line per e-mail, spreadsheet-safe.

## `folders` (type: `string`):

Folders found on the server and what was read in each.

## `runSummary` (type: `string`):

Counts, billing, AI usage, stop reason, failure codes.

## `failedInputs` (type: `string`):

Problems with a stable code: AUTH_MISSING, AUTH_FAILED, SERVER_UNREACHABLE, FOLDER_NOT_FOUND, IMPORT_TOO_LARGE, AI_KEY_INVALID...

# 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 = {
    "source": "demo"
};

// Run the Actor and wait for it to finish
const run = await client.actor("badr_xba/imap-mail-intelligence").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 = { "source": "demo" }

# Run the Actor and wait for it to finish
run = client.actor("badr_xba/imap-mail-intelligence").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 '{
  "source": "demo"
}' |
apify call badr_xba/imap-mail-intelligence --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,badr_xba/imap-mail-intelligence"
        }
    }
}
```

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/9j87zbqdYWZYttFi1/builds/K1X1bN9bj5kU5a2Ow/openapi.json
