Skip to main content
Glama
MailMCP

MailMCP

README.md
# Cloud Mail MCP

Self-hosted email for AI agents. Cloud Mail MCP connects all your mailboxes, keeps a fast local index of your mail, and lets AI agents (Claude, ChatGPT, or your own app) read, search, organize and send mail over MCP. Each agent has its own permissions per mailbox, sends can wait for your approval, and every action is recorded in an audit log.

> **Status: v0.1, early but working end to end** for IMAP/SMTP mailboxes (cPanel and other hosting mail, Apple iCloud, Gmail via app password). Microsoft 365 and the Gmail API are next. See [docs/SPEC.md](docs/SPEC.md).

## Install on your server

You need a Linux server (or any machine) with Docker. If you run your own fork, use your repository in place of `Cloud-Mail-Mcp/cloud-mail-mcp`.

```bash
# With your own domain: automatic HTTPS certificates (point the domain's DNS at the server first)
curl -fsSL https://github.com/Cloud-Mail-Mcp/cloud-mail-mcp/releases/latest/download/install.sh | sh -s -- --domain mail.example.com

# Without a domain: plain HTTP on port 8787 (trusted networks only)
curl -fsSL https://github.com/Cloud-Mail-Mcp/cloud-mail-mcp/releases/latest/download/install.sh | sh
```

The installer creates a `cloud-mail-mcp/` folder with `compose.yml` and a `.env` (it generates a random database password), then starts everything. Open the address it prints and the **setup wizard** walks you through it:

1. **Your account:** the owner login.
2. **Server:** a name, and the public URL your AI clients will use.
3. **Mail storage:** this server's disk, or S3-compatible storage (AWS S3, Cloudflare R2, Backblaze B2, MinIO).
4. **Sync:** how much mail to download.
5. **Finish:** back up the encryption key, then add your first mailbox.

The wizard only appears until it's finished. Everything after that is managed in the admin panel.

Installer options: `--domain NAME`, `--dir PATH`, `--port N`, `--edge` (follow every change instead of stable releases), `--auto-update` (apply updates daily), `--repo OWNER/NAME`.

> **Back up your encryption key.** It encrypts every saved mail password and all stored mail, and it is deliberately not in the database:
> `cd cloud-mail-mcp && docker compose cp mailmcp:/data/master.key ./master.key.backup`

**Other ways to install:**

- **[Enhance](docs/install/enhance.md):** GitHub deploy plus Node.js; no build step, and updates arrive automatically.
- **[cPanel, Plesk or any Node.js host](docs/install/shared-hosting.md):** the prebuilt `cloud-mail-mcp-node` zip.
- **[Easypanel, Coolify, Dokploy, CapRover, Portainer](docs/install/panels.md):** the Docker image.

### Updates

**Settings → Updates** shows the running version and whether a newer one exists. **Update now** pulls the new image and restarts Cloud Mail MCP. Your data, settings and key are kept, and database changes apply automatically. You can also choose:

- **Stable releases** (tagged versions) or **Every change** (the `edge` build of `main`).
- Daily automatic updates (`AUTO_UPDATE=true` in `.env`).

From the command line: `cd cloud-mail-mcp && docker compose pull && docker compose up -d`.

### Publishing your own version (forks)

Nothing is tied to one GitHub account. Fork the repo and the included workflows publish everything under your fork:

- Every push to `main` builds `ghcr.io/<you>/<repo>:edge`.
- Every tag like `v1.2.0` builds `:1.2.0` and `:latest`, and creates a GitHub release with `install.sh` and `compose.yml` attached, already pointing at your repository.
- Installs made from your releases check **your** repository for updates.

One-time step after the first build: on GitHub open **Packages → your image → Package settings** and set visibility to **Public**, so servers can pull it without logging in.

### Try it locally from source

```bash
git clone https://github.com/Cloud-Mail-Mcp/cloud-mail-mcp mailmcp && cd mailmcp
docker compose -f deploy/docker-compose.yml up -d   # builds the image locally
```

Then open **http://localhost:8787**.

## Connect Claude, ChatGPT and other AI apps

Your MCP server URL is your Cloud Mail MCP address plus `/mcp`, e.g. `https://mail.example.com/mcp`. Apps that support MCP sign-in (OAuth) only need that URL: they send you to a Cloud Mail MCP page where you choose which mailboxes the app can use and what it may do in each. Claude and ChatGPT require an `https://` address.

| App                               | How                                                                                                                  |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| **Claude** (web, Desktop, mobile) | Settings → Connectors → **Add custom connector** → paste the URL → **Connect**                                       |
| **ChatGPT**                       | Settings → Apps & Connectors → Advanced → turn on **Developer mode**, then create a connector with the URL and OAuth |
| **Claude Code**                   | `claude mcp add --transport http cloud-mail-mcp https://mail.example.com/mcp`, then `/mcp` → Authenticate            |
| **Cursor, VS Code, others**       | Add a remote (HTTP) MCP server with the URL                                                                          |

Connected apps appear under **Agents**, where you can change their access, disable them or remove them. The admin panel's Agents page shows your exact URL and these steps.

**Apps without MCP sign-in:** create an agent with an API key under Agents and send it as a header:

```bash
claude mcp add --transport http cloud-mail-mcp https://mail.example.com/mcp --header "Authorization: Bearer cmcp_…"
```

Or, for clients that only run local servers (`claude_desktop_config.json` style):

```json
{
  "mcpServers": {
    "cloud-mail-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://mail.example.com/mcp",
        "--header",
        "Authorization:${CLOUD_MAIL_MCP_AUTH}"
      ],
      "env": { "CLOUD_MAIL_MCP_AUTH": "Bearer cmcp_…" }
    }
  }
}
```

### Tools agents get (filtered by their permissions)

| Read                                                                                                                            | Organize                                                                                                                      | Send                                                                   | Folders                                           |
| ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------- |
| `list_accounts`, `list_folders`, `list_messages`, `search_messages`, `get_message`, `get_thread`, `get_attachment`, `list_tags` | `mark_messages`, `move_messages`, `delete_messages`, `mark_spam`, `tag_messages`, `unsubscribe`, `add_mailboxes` (if allowed) | `send_email`, `reply`, `forward`, `create_draft`, `get_pending_action` | `create_folder`, `rename_folder`, `delete_folder` |

Search syntax: free text plus `from:` `to:` `subject:"…"` `in:<folder>` `tag:<tag>` `after:YYYY-MM-DD` `before:` `has:attachment` `is:unread` `is:flagged`.
Prompts: `triage_inbox`, `summarize_thread`, `draft_reply`.

## Spam and AI sorting

- **Spam / Not spam** in Mail (and the `mark_spam` tool) moves mail to the account's Spam folder,
  where Gmail, iCloud and many other servers learn from it, and sets the `$Junk` keyword that mail
  apps use. "Always send mail from this sender to Spam" blocks a sender; manage the list under
  **Spam & sorting**.
- Each message shows what your mail server reported about it: whether the sender was verified
  (SPF, DKIM, DMARC) and any spam score, with a warning on suspicious mail.
- **AI sorting** (optional, uses your Anthropic API key) tags each new message by what it is:
  personal, solicitation, marketing, newsletter, social media, notifications, receipts, security,
  spam. Tags are editable, each can archive, mark read or move to Spam automatically, and your
  corrections teach it. Filter Mail by tag, search with `tag:social`, or ask Claude to act on a
  whole kind of mail ("delete all social media emails").

## Moving to a new mail host

Changing hosting providers? Add the address twice under **Accounts**, once with the old server's
settings and once with the new one. Cloud Mail MCP labels each login with its server name (you can
rename the labels, e.g. "Old host" / "New host"). Then open **Migrations**:

1. Pick the old account as **Copy from** and the new one as **Copy to**. **Preview folders**
   shows where each folder will go (Inbox, Sent, Trash and so on are matched even when they're
   named differently, and missing folders are created).
2. Choose **Both ways** if mail may still arrive at the old server while DNS changes, and keep
   **Keep copying new mail** on.
3. **Start migration.** Every folder is copied with its read and flagged state. Messages already on
   the other side are skipped (matched by Message-ID), and nothing is ever deleted, so it's safe
   to run again. New mail is copied every couple of minutes
   (`MIGRATION_INTERVAL_SECONDS`, default 120).
4. When your MX records point to the new server and the old one has gone quiet, click **Finish**.

If a password or server address changes later, update it on the account's page under **Login &
server settings**. Cloud Mail MCP tests the new settings before saving them.

## How it's built

- **Postgres:** metadata, permissions, and the full-text search index. Shared tables keyed by account, benchmarked in [SPEC §4a](docs/SPEC.md).
- **Blob store:** message bodies, raw source and attachments, compressed and AES-256-GCM encrypted per account. Stored on local disk or any S3-compatible service (configured in **Settings**).
- **Worker:** pg-boss job queue, newest-first resumable sync, IMAP IDLE for instant new mail, a daily full reconcile, and Gmail's daily download limit respected.
- **Modules:** every provider is a plug-in module behind one [Module API](packages/module-sdk/src/index.ts).

```
apps/server        HTTP: MCP endpoint, REST API, admin panel
apps/worker        Sync jobs, IDLE watchers, scheduler
apps/admin         Admin panel (React + Vite + Tailwind)
packages/core      Sync engine, mail service, permissions, approvals, crypto
packages/db        Drizzle schema + migrations
packages/search    Search syntax + Postgres search driver
packages/storage   Blob store drivers (fs, s3) + encryption
packages/module-sdk  The Module API
modules/imap       IMAP/SMTP connector
deploy/            compose.yml (production), install.sh, docker-compose.yml (development)
.github/workflows  CI, and image/release publishing
```

## Development

Requires Node 22+ (`nvm use`), Docker, and pnpm (via `corepack enable`).

```bash
pnpm install
cp .env.example .env                       # only the database URL
pnpm db:up && pnpm db:migrate              # Postgres on localhost:5433
pnpm --filter @cloud-mail-mcp/admin build
pnpm --filter @cloud-mail-mcp/server start        # http://127.0.0.1:8787/admin/
pnpm --filter @cloud-mail-mcp/worker start        # in another terminal
```

`pnpm dev` runs everything with live reload (admin on http://localhost:5173/admin/).

**Test mail server.** GreenMail provides three throwaway mailboxes (see `deploy/docker-compose.yml`):

```bash
docker compose -f deploy/docker-compose.yml --profile testmail up -d greenmail
pnpm --filter @cloud-mail-mcp/worker seed -- --count 3000   # realistic mail for alice@example.test
pnpm --filter @cloud-mail-mcp/worker sync-once              # sync all accounts in the foreground
```
In the admin panel choose _Other IMAP server_ with host `127.0.0.1`, IMAP 3143, SMTP 3025, TLS off, user `alice@example.test` / `alice-pass-123`.

The dev stack's Compose project is `mailmcp-dev`, so it never collides with a production install on the same machine.

**Checks:** `pnpm typecheck` · `pnpm lint` · `pnpm test`. Tests include integration and end-to-end suites against GreenMail; they skip themselves if it isn't running.

## Releasing a new version

One command updates every install method together:

```bash
pnpm release 0.2.0 --dry-run   # preview
pnpm release 0.2.0             # bump versions, check, tag v0.2.0, push
```

It checks that `main` is clean, in sync and green on CI. It then bumps the version (including the Easypanel template's pinned image), runs lint and typecheck, and pushes the tag. GitHub Actions builds the Docker image and the Node.js bundle. **Only if both succeed** does it publish them all at once:

- Docker image `:0.2.0` / `:latest`
- the `dist` branch for Enhance and git-deploy hosts
- the GitHub release with the installer, Compose file and zip

Installs see the update after that, through Settings → Updates, auto-deploy, or the updater. Every push to `main` publishes the `edge` image and the `dist-edge` branch the same way.

## License

[AGPL-3.0](LICENSE).