mail-mcp

mail-mcp

A self-hosted MCP server that gives AI agents full email superpowers.

Category
Visit Server

README

<div align="center">

<img src="https://mailts.anishhs.com/logo-icon.png" alt="mail-mcp" width="38" />

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.

CI License: MIT Node @mailts/core

</div>


โœจ 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

๐Ÿš€ 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-password
npm install && npm run dev
# โ†’ Listening on http://localhost:3000/mcp

Multi-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-password

The mail_mcp_accounts table is created automatically on first run. Add more accounts via the agent at any time.


๐Ÿ”ง Configuration

Variable Required Default Description
API_KEYS โœ… โ€” Comma-separated Bearer tokens for MCP auth
DATABASE_URL Multi-account โ€” Standard Postgres connection string
MAIL_MCP_SECRET With DB โ€” Encryption key for credentials at rest
SERVER_URL Recommended โ€” Public URL โ€” shown in agent password setup guides
PORT No 3000 HTTP listen port
IMAP_HOST / SMTP_HOST No โ€” Single default account from env

Copy .env.example to .env and 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

<details> <summary><strong>Read & Search</strong></summary>

Tool Description
list_emails List emails with optional filters (unread, limit)
get_email Fetch full email โ€” text/html via BODYSTRUCTURE, attachment metadata from structure tree
search_emails Search by from, to, subject, body, date range, flags
get_thread Fetch full conversation thread by Message-ID
get_attachments List attachment metadata or download with base64 content
watch_inbox Watch for new emails via IMAP IDLE

</details>

<details> <summary><strong>Send & Compose</strong></summary>

Tool Description
send_email Send immediately via SMTP or HTTP transport
reply_email Reply to a message โ€” auto-fills In-Reply-To / References
reply_all_email Reply-all, excluding self from recipients
forward_email Forward with original body quoted
save_draft Save to Drafts folder
send_calendar_invite Send iCal VEVENT with RSVP

</details>

<details> <summary><strong>Bulk & Templates</strong></summary>

Tool Description
bulk_send Send personalised emails to a list with per-row variable substitution
bulk_send_calendar_invite Send individual calendar invites to a list
define_template Define a reusable email template with variables
list_templates List defined templates
preview_template Preview a template with sample data
send_template Send using a defined template

</details>

<details> <summary><strong>Queue</strong></summary>

Tool Description
queue_email Enqueue for async delivery with retries and priority
queue_stats View queue depth and processing stats
queue_pause / queue_resume Pause or resume the queue
queue_drain Wait for queue to empty
queue_cancel Cancel a queued message
list_dead_letters List permanently failed messages
retry_dead_letter Retry a dead-lettered message

</details>

<details> <summary><strong>Flags & Organisation</strong></summary>

Tool Description
mark_emails Set/clear seen, flagged, answered
move_emails Move to another mailbox (IMAP MOVE or COPY+DELETE)
copy_emails Copy to another mailbox
delete_emails Permanently delete (mark + EXPUNGE)
sync_incremental Fetch messages changed since a CONDSTORE mod-sequence

</details>

<details> <summary><strong>Mailboxes</strong></summary>

Tool Description
list_mailboxes List all IMAP folders
get_mailbox_status Message counts and sync metadata
create_mailbox Create a new folder
rename_mailbox Rename a folder
delete_mailbox Delete a folder

</details>

<details> <summary><strong>Accounts</strong></summary>

Tool Description
list_accounts List accounts with default status and capabilities
add_account Add account to DB โ€” returns curl command for password setup
update_account Update host, port, user, label
remove_account Remove account from DB
set_default_account Switch the default account
reload_config Reload accounts without restarting
health_check Live IMAP/SMTP connectivity probe

</details>


๐Ÿ”‘ 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
GET /health None Server health check
GET /accounts API_KEYS List accounts (no passwords)
PATCH /accounts/:name API_KEYS Update non-sensitive fields
DELETE /accounts/:name API_KEYS Remove an account
POST /accounts/:name/password MAIL_MCP_SECRET Set encrypted credentials

The password endpoint deliberately uses MAIL_MCP_SECRET โ€” not API_KEYS โ€” so the agent (which knows API_KEYS) is cryptographically prevented from setting credentials.


๐Ÿšข Deployment

Docker

docker build -t mail-mcp .
docker run -p 3000:3000 --env-file .env mail-mcp

Cloud 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, deploys
  • Enter version (e.g. v0.1.0) โ†’ rollback to that existing tag's original commit
  • Source code on main is never modified by deploys or rollbacks

Two separate approval gates:

Gate Environment Action
1 tag Create / validate the release tag
2 production Build image and deploy to Cloud Run

Required GitHub secrets:

GCP_PROJECT_ID ยท GCP_REGION ยท GCP_WORKLOAD_IDENTITY_PROVIDER ยท GCP_SERVICE_ACCOUNT ยท SERVER_URL

GCP 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 <img src="https://mailts.anishhs.com/logo-icon.png" alt="mailts" width="12" /> @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 exposure
  • textOnly fetch mode โ€” BODYSTRUCTURE-driven, fetches text/plain and text/html only in a single round-trip
  • Native 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


<div align="center">

Built by Anish Shekh

GitHub LinkedIn Website

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured