sendless-mcp
by SirMacke
README.md
# sendless-mcp
An IMAP [MCP](https://modelcontextprotocol.io) server that lets an AI agent
read your mail and write drafts, but never send. You review each draft in your
own mail client and send it yourself.
- **No send path.** There is no SMTP code and no send tool. The broker accepts a
fixed list of named operations. It has no move, no raw IMAP and no general
delete.
- **The agent never holds the password.** A small broker process runs under its
own systemd user and is the only process that holds the IMAP password. The
agent's MCP client talks to it over a Unix socket.
- **Safe draft revision.** `update_draft` copies the old version to Trash and
confirms the copy. It then appends the revision and reads it back. Only after
that does it remove the old version, with `UID EXPUNGE` on that one UID. If
anything changed in between, both versions are kept.
- **Attachments from one folder only.** The client attaches files only from a
private 0700 outbox folder. It refuses symlinks, hard links and hidden files.
Linux with systemd only. Python 3.11+, standard library only. Windows and macOS
are not supported yet.
## Threat model
The agent is assumed to be **well-meaning but steerable**. Mail it reads can
contain prompt injection. The agent may also make mistakes with real
consequences. sendless-mcp limits what any sequence of tool calls can do:
| Risk | What stops it |
|---|---|
| The agent sends mail, or is tricked into sending it | No send code exists. Drafts wait in Drafts for a person. If your provider can do it, also give the IMAP login no SMTP rights. |
| The agent leaks or misuses the IMAP password | The password lives only in the broker. systemd hands it over with `LoadCredential=`, and the broker runs as a separate `DynamicUser`. The agent's user cannot read the credential file, the broker's memory or its environment. |
| The agent deletes, moves or bulk-flags mail | The broker allowlists operations and arguments before it logs in. Only `update_draft` can set `\Deleted`, and only on the single verified draft it replaced, after a confirmed copy to Trash. |
| The agent overwrites a draft you are editing | A revision is refused unless the reference still points to the same message (UIDVALIDITY plus UID). The old draft is removed only if its flags and size are unchanged. |
| Mail content tricks the agent into attaching `~/.ssh/id_ed25519` | Attachments must be regular files inside the outbox. The client opens each path component with `O_NOFOLLOW` and refuses hard links. It re-checks the opened file's real path. |
| A crafted request exhausts the broker | Every request, response, header, body, attachment count and size is bounded. The broker serves one call at a time. |
| A changed config points the broker at another server | The broker opens its config through a chain of folders from `/`, without following symlinks, and refuses any file or folder that a non-root user can write. |
| Another local user plants a fake broker socket | Before connecting, the client checks that the socket and every folder above it are owned by root and not writable by others. |
| A client holds the broker by sending slowly | A whole request must arrive within 30 seconds and the reply be taken within 10, however slowly the bytes trickle. |
**Not covered.** The outbox rules stop mistakes and injected instructions. They
do not stop a deliberately hostile agent: the client runs as the agent's user,
so such an agent can copy any file it can read into the outbox, or talk to the
socket directly. What still holds against it: the broker's allowlist, the
password isolation, no sending, and your review before anything leaves. Also
not covered:
- a compromised root account;
- a malicious IMAP server;
- what you approve and send yourself.
Treat mail content as untrusted data, as the server's MCP instructions tell
the agent.
## Compared with other IMAP MCP servers
As of December 2026 there are dozens of email MCP servers. Most can send. A
growing number have a read-only or drafts-only mode, but almost all of them
give the agent's own process the password, usually through environment
variables in the MCP client config. These are the closest:
| Project | Send | Credentials | Drafts | How sendless-mcp differs |
|---|---|---|---|---|
| [ni-c/imap-mcp](https://github.com/ni-c/imap-mcp) (TypeScript) | No, by design | Env var, removed from the env after it is read; same process as the agent's server | Create | Closest in philosophy, and it has stronger prompt-injection fencing and cross-platform packaging. It offers move and delete behind confirmation. sendless-mcp puts the password under a separate uid and adds draft revision. |
| [florianbuetow/imap-mini-mcp](https://github.com/florianbuetow/imap-mini-mcp) (TypeScript) | No | Env vars in the client config | Create, reply, update | It also revises drafts, and it can move mail. sendless-mcp adds credential isolation and a Trash copy confirmed before the old draft is expunged. |
| [scaratec/imap-mcp](https://github.com/scaratec/imap-mcp) (Python) | No | Secret store, OAuth; its docs recommend a separate OS user or sidecar | Create, update | The closest security design, and richer: OAuth, a policy engine and auditing. sendless-mcp ships the separate-user split as its default install, with less to configure. |
| [randomparity/rusty-imap-mcp](https://github.com/randomparity/rusty-imap-mcp) (Rust) | Only in its `full` posture; `draft-safe` by default | OS keychain, same user | Create | A safe default, but sending is a configuration switch away, and the agent's user can reach the keychain. |
| [pirafrank/email-imap-mcp-plugin](https://github.com/pirafrank/email-imap-mcp-plugin) (Python) | No | `${ENV}` references in its config | Create | It also limits attachments to configured folders. It has no credential isolation and no draft update. |
Others keep the password away from the agent in other ways:
- [dryas/mail-shadow-mcp](https://github.com/dryas/mail-shadow-mcp) syncs mail
into a local SQLite copy that the agent searches. It cannot send. Its one
write tool, `delete_mail`, moves a message to a configured trash folder with
IMAP MOVE.
- [wildsurfer/your-mail-mcp](https://github.com/wildsurfer/your-mail-mcp)
mirrors mail locally and is read-only.
- [xercn/imap-mcp](https://github.com/xercn/imap-mcp) holds encrypted passwords
on a remote server and can send after human approval.
Popular general-purpose servers have more features: many providers, OAuth,
search across accounts and sending. Examples are
[Wh1isper/mcp-email-server](https://github.com/Wh1isper/mcp-email-server),
[codefuturist/email-mcp](https://github.com/codefuturist/email-mcp) and
[nikolausm/imap-mcp-server](https://github.com/nikolausm/imap-mcp-server).
**Where sendless-mcp is weaker:**
- Linux and systemd only.
- Password (app password) login only: no OAuth, no STARTTLS.
- No prompt-injection fencing of message bodies beyond the instruction to
treat mail as untrusted.
- `read_message` returns the text body only. It does not list attachments.
- Fewer tools. That is deliberate.
## Quick start
These steps need root on the Linux machine where the agent runs. Replace
`work` with your mailbox key and `agent` with the agent's user.
1. **Make a dedicated login, if your provider allows it.** Many providers let
you create an app password or a second identity for the same mailbox.
Prefer one that can use IMAP but not SMTP. The server needs `UIDPLUS` and
`SPECIAL-USE` folders (`\Drafts`, `\Sent`, `\Trash`) for every tool. Most
hosted providers have both.
2. **Get a checkout and install it root-owned**, so the agent cannot change
the code that holds the password. The package is not on PyPI yet. Run the
remaining steps from the checkout, which also holds the example files:
```sh
git clone --branch v1.6.0 https://github.com/SirMacke/sendless-mcp.git
cd sendless-mcp
sudo python3 -m venv /opt/sendless-mcp
sudo /opt/sendless-mcp/bin/pip install .
```
3. **Write the config** from [examples/config.toml](examples/config.toml). It
holds no secrets.
```sh
sudo install -d -m 0755 /etc/sendless-mcp
sudo install -m 0644 examples/config.toml /etc/sendless-mcp/config.toml
sudoedit /etc/sendless-mcp/config.toml
```
4. **Store the password** in a root-only file. It holds only the password, on
one line. Keep it out of shell history:
```sh
sudo install -d -m 0700 /etc/sendless-mcp/work
sudo sh -c 'umask 077; cat > /etc/sendless-mcp/work/imap-password' # paste, Enter, Ctrl-D
```
5. **Install the systemd units** from [examples/systemd/](examples/systemd/).
Let the agent's user connect, then enable the socket:
```sh
sudo install -m 0644 examples/systemd/sendless-mcp@.socket examples/systemd/sendless-mcp@.service /etc/systemd/system/
sudo groupadd --system sendless-mcp
sudo usermod -aG sendless-mcp agent # takes effect at the agent's next login
sudo systemctl daemon-reload
sudo systemctl enable --now sendless-mcp@work.socket
```
6. **Create the outbox** as the agent's user, then check that the config
parses and names the right mailbox:
```sh
install -d -m 0700 ~/mail-outbox
/opt/sendless-mcp/bin/sendless-mcp work --check
```
7. **Register the MCP server** with your agent (below). Start a new session
and ask it to list the inbox.
Before you trust it with real mail, save and revise one test draft. Then
check in your mail client that the draft appears with the right From address
and the old version is in Trash.
### MCP client configuration
The client takes the mailbox key as its only argument. With a single mailbox
configured you can leave it out. Register one server per mailbox.
**Claude Code**:
```sh
claude mcp add --scope user work-mail -- /opt/sendless-mcp/bin/sendless-mcp work
```
or in `.mcp.json`:
```json
{
"mcpServers": {
"work-mail": {
"command": "/opt/sendless-mcp/bin/sendless-mcp",
"args": ["work"]
}
}
}
```
**Codex**, in `~/.codex/config.toml`:
```toml
[mcp_servers.work-mail]
command = "/opt/sendless-mcp/bin/sendless-mcp"
args = ["work"]
```
The client reads `/etc/sendless-mcp/config.toml` unless you pass `--config` or
set `SENDLESS_MCP_CONFIG`. It needs only the socket path and the outbox, and it
never reads the password.
## Tools
| Tool | What it does |
|---|---|
| `list_inbox` | Lists recent Inbox headers, newest first, without marking them read. Pages with `before`. |
| `read_message` | Reads one Inbox, Sent or Drafts message with `BODY.PEEK`. Returns headers and up to 30,000 characters of the text body. |
| `search_sent` | Searches Sent by `to`, `cc`, `text`, `message_id` or `reply_to` (In-Reply-To and References). |
| `search_drafts` | Searches Drafts by `to`, `message_id` or `reply_to`. |
| `save_draft` | Appends a new plain-text draft with the `\Draft` flag. Takes one recipient, an optional Inbox `reply_to` for threading and optional attachments. A repeated identical call returns `already_saved`. |
| `update_draft` | Replaces one draft with a revision. Omitting `attachments` keeps the old files, a list replaces them, `[]` drops them, and a list with `keep_attachments: true` adds to them. |
| `set_read` | Sets or clears `\Seen`. |
| `set_junk` | Sets or clears `$Junk` (and clears `$NotJunk`) without moving the message. |
When `reply_aliases` is configured, `save_draft` and `update_draft` also take a
`from_address`. It can be used only on a reply to an Inbox message addressed
solely to that alias, and only to the original's Reply-To or From address.
**Message references** look like `work:1700000000:42` (Inbox) or
`work:drafts:1700000000:42`. They hold the mailbox key, the folder, the
folder's UIDVALIDITY and the UID. A reference from another mailbox or folder,
or from before the server renumbered a folder, is refused.
**`update_draft` results:**
- `updated`: the revision is saved and the old version removed (a copy is in
Trash).
- `unchanged`: the draft already had this content.
- `saved_previous_kept`: the old draft changed during the call, so both
versions stay.
- `saved_previous_missing`: the old draft left Drafts during the call, for
example because it was sent.
## Limits and security notes
- **Sizes.** Inbox and search pages hold at most 30 messages. Bodies return at
most 30,000 characters, from the first 256 KiB of the message. A draft can
have at most 10 attachments, 20 MiB decoded in total. Filenames are cut to
150 UTF-8 bytes. 20 MiB of files makes a message of about 28.7 MB, and many
receiving servers refuse messages over 25 MB.
- **Drafts are plain text, with one To recipient.** There is no HTML, Cc or
Bcc. Add those in your mail client before sending.
- **Close a draft in your mail client before an agent revises it.** If your
client still has unsaved local edits, it may save them as a second draft.
Some clients save an edit by replacing the draft. The agent's reference then
stops working and `update_draft` refuses, so the agent must search Drafts
again and read your version first.
- **Trash is the only undo** for a replaced draft. Check your provider's Trash
retention.
- **One call at a time.** Each mailbox's broker serves one connection at a
time, with a 35-second client timeout (180 seconds for draft writes). That
serialization is what makes repeated identical saves deduplicate. A request
must arrive within 30 seconds.
- **Sandbox.** The example service unit scores 1.1 ("OK") with
`systemd-analyze security`. CI installs it unchanged and runs a call through
it over TLS. If you loosen it, keep `DynamicUser`, `LoadCredential` and
`ProtectHome`.
- **Junk.** `set_junk` only flags the message. It never moves it to the Junk
folder, which many providers purge automatically.
- **Errors.** IMAP server replies are never passed to the agent. Errors are
fixed, generic messages.
- **Socket access.** The socket group decides who can use the mailbox. Anyone
who can connect to the socket can use every tool on it.
- **Message-IDs.** Generated Message-IDs look like
`<{id_prefix}-draft-{sha256}@{your domain}>`. The hash is taken over the
draft's content, so an identical retry is recognised.
See [SECURITY.md](SECURITY.md) to report a vulnerability.
## How it works
```
agent (MCP host) ── stdio ──> sendless-mcp work runs as the agent's user, no password
│ one JSON line per call, attachments as bytes
▼
/run/sendless-mcp-work.sock root:sendless-mcp 0660
│ systemd socket activation
▼
sendless-mcp work broker DynamicUser, LoadCredential=imap-password
│ fixed IMAP commands over TLS
▼
IMAP server
```
Both roles are the same Python module. The client only relays calls and reads
attachment files from the outbox. The broker checks every request against the
allowlist before it logs in, and it never receives or opens a file path.
## Development
```sh
python3 -m venv .venv && .venv/bin/pip install -e .
.venv/bin/python -m unittest discover -s tests -v
```
The tests run offline against a fake IMAP server and need Linux, because the
outbox checks use `/proc/self/fd`. CI runs them on Python 3.11 to 3.14.
CI also runs [tests/systemd/check.sh](tests/systemd/check.sh). It installs the
example units unchanged and calls `list_inbox` through the client and the
sandboxed broker, over TLS to a local fake IMAP server. The script changes
system state, so run it only on a disposable machine.
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues