Mail Bridge
by tillheidrich
README.md
# Mail Bridge
**English** · [Deutsch](README.de.md)
Mail Bridge connects your email mailboxes and your calendar to Claude, ChatGPT and other AI agents. You host it yourself. Agents read, sort, write drafts and, if you allow it, send. You keep working in your normal mail app at the same time.
It is a remote [MCP](https://modelcontextprotocol.io/) server with its own OAuth 2.1 authorisation server and a web dashboard. The dashboard is available in English and German.
## Features
- **Several mailboxes per connection.** An agent sees exactly the mailboxes you select when you connect it.
- **Read, search, organise.** Read mails and attachments (PDF as text), move, flag, move to trash. Nothing is ever deleted for good.
- **Drafts.** Replies with the right subject and threading, attachments (uploaded or taken from another mail), HTML mails and a signature per mailbox. Drafts are normal drafts, visible in every mail app.
- **Alias addresses.** Replies go out from the address the mail was sent to, if that address is listed as an alias of the mailbox.
- **Sending with a limit.** `send_draft` only sends messages that already sit in the Drafts folder and are marked as drafts. You set the daily limit in the dashboard (0 = unlimited). Sending is off server-wide until you set `ALLOW_SEND=true`.
- **Unsubscribe from newsletters.** Using the mail's `List-Unsubscribe` header: RFC 8058 one-click, or an unsubscribe mail as a draft.
- **Calendar.** Read and create events via CalDAV (tested with iCloud). Deleting is not possible.
- **Morning overview.** `triage_overview` shows unread and unanswered mail across all mailboxes.
- **Dashboard.** Mailboxes with a connection test before saving, presets for common providers, connected agents and their permissions, disconnect with one click, activity log of every action (without mail content).
Why it is built this way: [docs/PERSONAS.md](docs/PERSONAS.md).
## What is stored on the server
Mailbox credentials (AES-256-GCM encrypted), OAuth clients, hashed tokens, settings and the activity log of the last 90 days. **No mail.** Content is fetched live from your mail provider on every call and dropped after the answer.
## Quick start with Docker Compose
```bash
git clone https://github.com/tillheidrich/mail-bridge-mcp.git
cd mail-bridge-mcp
cp .env.example .env
# Fill in BASE_URL, ENCRYPTION_KEY, SESSION_SECRET and ADMIN_PASSWORD in .env
openssl rand -hex 32 # once for ENCRYPTION_KEY, once for SESSION_SECRET
docker compose up -d
```
The bridge listens on `127.0.0.1:3000`. Put a reverse proxy with HTTPS in front (Caddy, Traefik, nginx, Coolify). Claude and ChatGPT only connect over HTTPS.
**Important:** keep `ENCRYPTION_KEY` safe, for example in a password manager. If it is lost, all mailbox passwords have to be entered again.
Then sign in at `BASE_URL` as `admin` with `ADMIN_PASSWORD`, set your own password and remove `ADMIN_PASSWORD` from `.env`.
### Configuration
| Variable | Required | Meaning |
|---|---|---|
| `BASE_URL` | yes | Public https address, without trailing slash |
| `ENCRYPTION_KEY` | yes | 64 hex characters, encrypts the mailbox passwords |
| `SESSION_SECRET` | yes | At least 32 random characters |
| `ADMIN_PASSWORD` | first start | Password for the user `admin` (min. 12 characters). Without it, a random password is printed to the log once |
| `ALLOW_SEND` | no | `true` lets agents get the “send” permission. Default: off |
| `SEND_DAILY_LIMIT` | no | Initial daily send limit, default 100. Changeable in the dashboard |
| `DRAFT_FROM_NAME` | no | Sender name if none is set for the mailbox |
| `DEFAULT_LANG` | no | `en` or `de` when the browser asks for neither. Default `en` |
| `CALENDAR_TZ` | no | Time zone for events and times in the dashboard, default `Europe/Berlin` |
| `CALDAV_ALLOWED_HOSTS` | no | Allowed CalDAV servers, default `icloud.com` |
| `TRUST_PROXY` | no | Number of proxies in front of the bridge. Default 1 with https, else 0 |
| `ALLOW_SIGNUP` | no | `true` lets further users sign up. Default: off |
| `ALLOW_CUSTOM_MAIL_PORTS` | no | `true` allows mail server ports other than 993/143 and 465/587/25 |
## Connect Claude and ChatGPT
The MCP address is shown at the top of the dashboard: `BASE_URL/mcp`.
- **Claude:** Settings → Connectors → Add custom connector → enter the address.
- **ChatGPT:** chatgpt.com/plugins → “Create MCP App” → enter the address. Depending on your plan, developer mode has to be on.
On first connect the bridge opens in your browser. There you choose mailboxes and permissions for exactly this connection:
| Permission | Allows |
|---|---|
| `mail:folders` | List folders |
| `mail:read` | Read mails, attachments, the overview and the signature |
| `mail:search` | Search |
| `mail:modify` | Move, flag, move to trash, one-click unsubscribe |
| `mail:draft` | Create drafts, store the signature |
| `mail:send` | Send existing drafts (only with `ALLOW_SEND=true`) |
| `cal:read` | Read calendars |
| `cal:write` | Create events |
An agent only sees the tools it has a permission for.
## Tools
`list_accounts`, `list_folders`, `list_messages`, `read_message`, `read_attachment`, `search_messages`, `triage_overview`, `move_message`, `flag_message`, `unsubscribe`, `create_draft`, `send_draft`, `get_signature`, `set_signature`, `list_calendars`, `list_events`, `create_event`.
Suggested working rules for your agent: [skills/mail-assistant.md](skills/mail-assistant.md).
## Providers
The form has presets for IONOS, Strato, All-Inkl, Hetzner, mailbox.org, Posteo, GMX, WEB.DE, Telekom, Gmail (app password) and iCloud. Any other provider with IMAP and SMTP works with its own server settings.
Microsoft 365 and Outlook.com no longer accept password logins and are not supported at the moment.
## Security
Threat model, limits and how to report a vulnerability: [SECURITY.md](SECURITY.md). In short:
- Every agent gets its own token with its own permissions. Disconnecting in the dashboard locks it out immediately.
- Mail content is data for agents, not instructions; the tool descriptions say so. Prompt injection cannot be ruled out inside the model, which is why sending, senders, the send limit and deleting are restricted outside the model.
- The bridge only connects to public mail and calendar servers and never fetches URLs an agent passes in.
## Development
```bash
npm ci --include=dev
npm run dev # tsx, port 3000
npm test # node:test with its own database in a temp folder
npm run build
```
To test against a mail server on your local network: `ALLOW_PRIVATE_MAIL_HOSTS=true` (development only).
Contributions are welcome. Please open an issue first; for security issues use the route in SECURITY.md.
## Origin and licence
Mail Bridge builds on [imap-mcp-server](https://github.com/mkrasselt1/imap-mcp-server) by Michael Krasselt (OAuth server, IMAP access, basic tools) and adds several mailboxes per connection, drafts, sending with a limit, calendar, unsubscribe, the activity log and the dashboard.
MIT licence, see [LICENSE](LICENSE). Built by [Heidrich Digital](https://heidrich-digital.de).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues