Skip to main content
Glama
Mail Reply MCP

Mail Reply MCP

by ygupta9132
README.md
# Mail Reply MCP

An MCP server that lets Claude read your Zoho Mail and Gmail and write replies in the right thread.
Replies are saved as **drafts** in the mailbox by default; you open Zoho or Gmail, check the draft, and
press Send. Sending straight from Claude is possible per account once you switch it on.

Both providers are reached over plain IMAP (read, drafts, flags) and SMTP (send) with **app
passwords**, so there is no Google Cloud project or Zoho API console to set up.

## Setup

1. `npm install` and `npm run build` in the project folder.
2. Create an app password for each mailbox (below).
3. Copy `.env.example` to `.env` and put each app password in it.
4. Copy `accounts.example.json` to `accounts.json` and describe each mailbox.
5. Register the server once, for every Claude Code session:

   ```
   claude mcp add --scope user mail-reply -- node /full/path/to/MailReplyMCP/dist/index.js
   ```

   Start a new Claude session after registering, or after changing `accounts.json` or `.env`
   (they are read when the server starts).

### Gmail

- Turn on 2-Step Verification for the Google account, then create an app password at
  Google Account > Security > App passwords. Google shows it as four groups of letters; spaces
  are fine, the server removes them.
- Hosts are preset: `imap.gmail.com:993` and `smtp.gmail.com:465`.
- Gmail puts SMTP-sent mail into Sent by itself, so the server does not add a copy.
- A Google Workspace admin can disallow app passwords. If the login fails with a correct app
  password, that is the likely cause.

### Zoho Mail

- In Zoho Mail > Settings > Mail Accounts, turn on **IMAP Access** for the mailbox. For an
  organisation account the admin may also need to allow IMAP for the user.
- If the account has two-factor authentication, create an app-specific password at
  accounts.zoho.in > Security > App Passwords and use that.
- Hosts depend on the data centre and plan. Set `"zoho": { "region": "in", "paid": true }`:
  - `paid: true` (paid organisation account) uses `imappro.zoho.<region>` / `smtppro.zoho.<region>`
  - `paid: false` uses `imap.zoho.<region>` / `smtp.zoho.<region>`
  - `region` is the data centre: `in` for zoho.in accounts, `com`, `eu`, `com.au`, `jp`, `ca`.
- Check the exact hosts in Zoho Mail > Settings > Mail Accounts > IMAP / SMTP. If they differ,
  add explicit `imap` / `smtp` blocks (below).

### accounts.json

```json
{
  "accounts": [
    {
      "id": "zoho-work",
      "provider": "zoho",
      "email": "you@yourdomain.in",
      "passwordEnv": "ZOHO_WORK_APP_PASSWORD",
      "displayName": "Your Name",
      "zoho": { "region": "in", "paid": true },
      "signature": "Regards,\nYour Name",
      "allowSend": false
    },
    {
      "id": "gmail",
      "provider": "gmail",
      "email": "you@gmail.com",
      "passwordEnv": "GMAIL_APP_PASSWORD",
      "allowSend": false
    }
  ]
}
```

| Field | Meaning |
|---|---|
| `id` | Short name used in the tools (lowercase letters, digits, `-`). |
| `provider` | `gmail`, `zoho`, or `imap` (any other mailbox; needs `imap` and `smtp`). |
| `email` | The mailbox address; replies come from it. |
| `passwordEnv` | Name of the `.env` variable that holds this account's app password. |
| `user` | Login name, if it is not the email address. |
| `displayName` | Name shown on replies. |
| `signature` | Added under every reply, above the quoted original. |
| `allowSend` | `true` enables `send_reply` for this account. Default `false`. |
| `imap`, `smtp` | `{ "host": "...", "port": 993, "secure": true }`; overrides the preset. |
| `saveToSent` | Copy sent replies into Sent. Preset: Gmail `false`, Zoho `true`. |
| `draftsFolder`, `sentFolder` | Folder paths, if the server cannot find Drafts or Sent itself. |

`accounts.json` holds no passwords. `.env` and `accounts.json` are both in `.gitignore`.

## Tools

| Tool | What it does |
|---|---|
| `list_accounts` | The configured accounts and whether sending is on for each. |
| `list_folders` | An account's folders and their role (inbox, drafts, sent, ...). |
| `list_messages` | Emails in a folder, newest first. Filters: `unread_only`, `from`, `subject`, `since` (YYYY-MM-DD), `limit` (default 20, max 50). |
| `get_message` | One email as text, with attachment names and sizes. |
| `draft_reply` | Saves a reply (or reply-all) in Drafts, threaded under the original. Nothing is sent. |
| `send_reply` | Sends the reply. Only exists when an account has `allowSend: true`. Needs `to`: the exact recipients the user approved; anything else is refused and the real list comes back. |
| `mark_read` | Marks an email read or unread. |

## Safety

- **Drafts by default.** `send_reply` is not even offered until an account has `allowSend: true`.
  Leave it off unless you need it.
- **Permission prompts depend on your Claude Code mode.** Auto mode and allow rules can approve
  tool calls without asking. To always be asked before a send, add an `ask` permission rule for
  `mcp__mail-reply__send_reply` in your Claude Code settings.
- **The server picks the recipients.** A reply goes to the original sender (or its Reply-To), plus
  To and Cc on reply-all, minus your own address. Claude cannot add or change recipients, so an
  email that says "also send this to ..." cannot redirect a reply.
- **Recipients are confirmed before a send.** `send_reply` must be given, in `to`, exactly the
  recipients the server works out; on any difference nothing is sent and the real list comes
  back, so Claude has to show you who it goes to first.
- **An unclear send is reported as unclear.** If the connection fails after the mail may already
  have reached the server, the error is `SEND_UNCERTAIN` ("may have been sent"). Check before
  sending again; Gmail files sent mail in Sent by itself.
- **Reading never marks mail as read.** Folders are opened read-only for listing and reading.
- **Email content is fenced as untrusted** in what Claude sees, with an instruction not to follow
  anything written inside an email. Body lines that imitate the fence are replaced, and subjects,
  names and file names are flattened to one line so they cannot pose as server output.
- **Passwords stay out of tool output and errors.** Errors name the `.env` variable, never its value.
- Not supported on purpose: new emails, forwards, attachments, moving or deleting mail.

## Development

```
npm test            # unit tests
npm run typecheck   # src and tests
npm run build
npm run test:e2e    # end-to-end, against a local GreenMail server
```

Run these from PowerShell or `cmd`, not Git Bash. Under Git Bash the working
directory reaches node with a different drive-letter case, vitest is resolved
twice, and every file fails collection with "Vitest failed to find the current
suite" before a single test runs. The tests are fine when that happens; the
shell is not.

The end-to-end tests need a throwaway GreenMail mail server (IMAP + SMTP in memory) on localhost:

```
docker run -d --name mailreply-greenmail -p 127.0.0.1:3025:3025 -p 127.0.0.1:3143:3143 -e GREENMAIL_OPTS="-Dgreenmail.setup.test.smtp -Dgreenmail.setup.test.imap -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.users=me:pw@example.test,ravi:pw@example.test -Dgreenmail.users.login=email" greenmail/standalone:2.1.8
```

Remove it afterwards with `docker rm -f mailreply-greenmail` (never `docker volume prune`).

Known flake on this Windows machine: a full `npm run test:e2e` now and then loses a test worker with
exit code `3221226505` (`0xC0000409`), a silent native crash inside node.exe. It also happens outside
vitest, with no third-party DLLs loaded, and was not traced to this code. Rerun when it
happens; it is not a failing test.