mail-mcp
Allows reading, sending, searching, and managing emails via Gmail's IMAP/SMTP interface, including multi-account support, encryption, and attachment handling.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mail-mcplist my last 5 emails from inbox"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mail-mcp
A self-hosted MCP server that gives AI agents full email superpowers.
Read, search, send, reply, manage mailboxes and accounts โ over any SMTP/IMAP provider.
โจ Features
Feature | Description |
๐จ 20 MCP tools | Read, search, send, reply, forward, draft, flag, move, delete, bulk send, templates, queue |
๐ Secure multi-account | Credentials encrypted at rest (AES-256-GCM); passwords never pass through the agent |
โก Efficient reads | BODYSTRUCTURE-driven selective fetch โ text only, no attachment bytes wasted |
๐๏ธ Postgres-backed | Accounts managed at runtime via the agent; persists across restarts |
๐ Provider-agnostic | Gmail, Fastmail, Outlook, or any IMAP/SMTP server |
๐ณ Docker-ready | Single container; deploy to Cloud Run, Fly.io, Railway, or anywhere |
Related MCP server: Agent Email
๐ Quick Start
Single account (no database needed)
# .env
API_KEYS=your-secret-key
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USER=you@gmail.com
IMAP_PASS=your-app-password
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=you@gmail.com
SMTP_PASS=your-app-passwordnpm install && npm run dev
# โ Listening on http://localhost:3000/mcpMulti-account with Postgres
# .env
API_KEYS=your-secret-key
DATABASE_URL=postgresql://user:pass@host/dbname?sslmode=require
MAIL_MCP_SECRET=any-random-string-32-chars
SERVER_URL=https://your-server.example.com
# Optional default account (always loaded from env)
IMAP_HOST=imap.gmail.com
IMAP_USER=you@gmail.com
IMAP_PASS=your-app-password
SMTP_HOST=smtp.gmail.com
SMTP_USER=you@gmail.com
SMTP_PASS=your-app-passwordThe mail_mcp_accounts table is created automatically on first run. Add more accounts via the agent at any time.
๐ง Configuration
Variable | Required | Default | Description |
| โ | โ | Comma-separated Bearer tokens for MCP auth |
| Multi-account | โ | Standard Postgres connection string |
| With DB | โ | Encryption key for credentials at rest |
| Recommended | โ | Public URL โ shown in agent password setup guides |
| No |
| HTTP listen port |
| No | โ | Single default account from env |
Copy
.env.exampleto.envand fill in your values.
Config loading order
IMAP_HOST / SMTP_HOST โ always loaded as the "default" account
DATABASE_URL โ additionally loads more accounts from Postgres
Neither set โ startup error๐ง MCP Tools
Tool | Description |
| List emails with optional filters (unread, limit) |
| Fetch full email โ text/html via BODYSTRUCTURE, attachment metadata from structure tree |
| Search by from, to, subject, body, date range, flags |
| Fetch full conversation thread by Message-ID |
| List attachment metadata or download with base64 content |
| Watch for new emails via IMAP IDLE |
Tool | Description |
| Send immediately via SMTP or HTTP transport |
| Reply to a message โ auto-fills In-Reply-To / References |
| Reply-all, excluding self from recipients |
| Forward with original body quoted |
| Save to Drafts folder |
| Send iCal VEVENT with RSVP |
Tool | Description |
| Send personalised emails to a list with per-row variable substitution |
| Send individual calendar invites to a list |
| Define a reusable email template with variables |
| List defined templates |
| Preview a template with sample data |
| Send using a defined template |
Tool | Description |
| Enqueue for async delivery with retries and priority |
| View queue depth and processing stats |
| Pause or resume the queue |
| Wait for queue to empty |
| Cancel a queued message |
| List permanently failed messages |
| Retry a dead-lettered message |
Tool | Description |
| Set/clear seen, flagged, answered |
| Move to another mailbox (IMAP MOVE or COPY+DELETE) |
| Copy to another mailbox |
| Permanently delete (mark + EXPUNGE) |
| Fetch messages changed since a CONDSTORE mod-sequence |
Tool | Description |
| List all IMAP folders |
| Message counts and sync metadata |
| Create a new folder |
| Rename a folder |
| Delete a folder |
Tool | Description |
| List accounts with default status and capabilities |
| Add account to DB โ returns curl command for password setup |
| Update host, port, user, label |
| Remove account from DB |
| Switch the default account |
| Reload accounts without restarting |
| Live IMAP/SMTP connectivity probe |
๐ Secure Password Flow
Passwords never pass through the agent. The agent guides you to set them directly:
You: "Add my work Gmail, imap.gmail.com, work@company.com"
Agent: Account "work" saved. Set your credentials:
curl -X POST https://your-server/accounts/work/password \
-H "Authorization: Bearer <your MAIL_MCP_SECRET value>" \
-H "Content-Type: application/json" \
-d '{"imap_pass":"your-app-password","smtp_pass":"your-app-password"}'
Credentials are encrypted at rest. Account activates immediately.๐ HTTP Endpoints
Method | Path | Auth | Description |
|
| None | Server health check |
|
|
| List accounts (no passwords) |
|
|
| Update non-sensitive fields |
|
|
| Remove an account |
|
|
| Set encrypted credentials |
The password endpoint deliberately uses
MAIL_MCP_SECRETโ notAPI_KEYSโ so the agent (which knowsAPI_KEYS) is cryptographically prevented from setting credentials.
๐ข Deployment
Docker
docker build -t mail-mcp .
docker run -p 3000:3000 --env-file .env mail-mcpCloud Run (GCP)
gcloud run deploy mail-mcp \
--image gcr.io/YOUR_PROJECT/mail-mcp \
--region us-central1 \
--allow-unauthenticated \
--update-secrets="DATABASE_URL=DATABASE_URL:latest,API_KEYS=API_KEYS:latest,MAIL_MCP_SECRET=MAIL_MCP_SECRET:latest" \
--set-env-vars="SERVER_URL=https://your-service-url"See deploy/ for Fly.io, Azure Container Apps, and AWS App Runner guides.
CI/CD
Two workflows:
ci.yml โ runs automatically on every push to main and every PR:
Typecheck โ Build โ Test โ Security audit (parallel)
deploy.yml โ triggered manually from GitHub Actions โ Run workflow:
Leave version empty โ reads version from
package.json, creates git tag, deploysEnter version (e.g.
v0.1.0) โ rollback to that existing tag's original commitSource code on
mainis never modified by deploys or rollbacks
Two separate approval gates:
Gate | Environment | Action |
1 |
| Create / validate the release tag |
2 |
| Build image and deploy to Cloud Run |
Required GitHub secrets:
GCP_PROJECT_ID ยท GCP_REGION ยท GCP_WORKLOAD_IDENTITY_PROVIDER ยท GCP_SERVICE_ACCOUNT ยท SERVER_URLGCP Secret Manager secrets: DATABASE_URL, API_KEYS, MAIL_MCP_SECRET
Set up both environments in GitHub โ Settings โ Environments with required reviewers.
๐ ๏ธ Development
git clone https://github.com/anishhs-gh/mail-mcp
cd mail-mcp
npm install
cp .env.example .env # fill in your credentials
npm run dev # hot reload on http://localhost:3000
npm test # 22 unit tests
npm run build # production buildโก Powered by @mailts/core
mail-mcp is built on top of @mailts/core โ a modern, native TypeScript SMTP/IMAP library with zero legacy dependencies, built from the ground up for Node 18+.
What mailts brings to this MCP:
BODYSTRUCTURE parsing โ selective MIME section fetch means only text parts are downloaded when reading email; attachment bytes are never transferred unless explicitly requested
ImapSession.search()โ full IMAP SEARCH through the session lock, no raw client exposuretextOnlyfetch mode โ BODYSTRUCTURE-driven, fetches text/plain and text/html only in a single round-tripNative TLS, DKIM, OAuth2, IDLE โ zero legacy dependencies, built for Node 18+
SMTP queue with priority scheduling โ built-in retry logic, dead-letter handling, and external queue driver support
mailts is also open source โ check it out at github.com/anishhs-gh/mailts
๐ค Contributing
Contributions are welcome! Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md first.
๐ License
MIT ยฉ 2026 Anish Shekh
Built by Anish Shekh
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/anishhs-gh/mail-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server