Skip to main content
Glama
DeamonDev888

imap-smtp-mcp

by DeamonDev888

imap-smtp-mcp

Connect ANY mailbox to ANY AI agent. Expose Gmail, Outlook, Apple Mail (iCloud), Fastmail, ProtonMail, Yahoo, and every self-hosted server as Model Context Protocol tools, so any MCP-compatible agent (Claude Desktop, Hermes, your own scripts) can read, search, send, and manage email.

┌──────────────────┐  httpStream + SSE  ┌──────────────────┐  IMAP   ┌────────────┐
│  MCP client      │ ──────────────────►│ imap-smtp-mcp    │ ───────►│ Mail       │
│  (Claude,        │                    │ (this server)    │         │ server     │
│   Hermes, etc.)  │                    │                  │  SMTP   │ (any)      │
└──────────────────┘                    └──────────────────┘ ───────►└────────────┘

✨ Features

  • 8 MCP tools: server_info, list_mailboxes, list_emails, read_email, search_emails, send_email, mark_read, delete_email.

  • Universal: works with any IMAP/SMTP server (Gmail, Outlook, Fastmail, ProtonMail, Dovecot, Stalwart, Postfix, etc.).

  • Transport: FastMCP 3.x with httpStream (per-session, server-sent events) and stdio (for desktop integration).

  • Production-ready: graceful shutdown, persistent connections, structured logging, error handling.

  • No secrets in code: configuration via environment variables only.

Related MCP server: anymail-mcp

📦 Installation

Prerequisites

  • Node.js ≥ 18

  • An IMAP/SMTP-enabled mailbox

  • For Gmail/Yahoo/Microsoft: an app password (not your account password). See provider-specific notes below.

From npm (once published)

npm install -g imap-smtp-mcp
imap-smtp-mcp

From source

git clone https://github.com/YOUR_USERNAME/imap-smtp-mcp.git
cd imap-smtp-mcp
npm install
npm run build
npm start

Development mode (with hot reload)

npm run dev

⚙️ Configuration

All configuration is via environment variables. Create a .env file or export them in your shell / systemd unit.

Required

Variable

Description

IMAP_HOST

IMAP server hostname (e.g. imap.gmail.com)

IMAP_USER

IMAP username (often your full email address)

IMAP_PASS

IMAP password or app password

SMTP_HOST

SMTP server hostname (often same as IMAP host)

SMTP_USER

SMTP username

SMTP_PASS

SMTP password or app password

Optional

Variable

Default

Description

IMAP_PORT

993

IMAP port (993 for SSL, 143 for STARTTLS)

IMAP_SECURE

true

Use TLS (set false for STARTTLS or plaintext)

IMAP_REJECT_UNAUTHORIZED

false

Reject invalid TLS certs (set true for production)

SMTP_PORT

465

SMTP port (465 for SSL, 587 for STARTTLS)

SMTP_SECURE

true

Use TLS

SMTP_REJECT_UNAUTHORIZED

false

Reject invalid TLS certs

SMTP_FROM

SMTP_USER

"From" address (if different from SMTP_USER)

FASTMCP_TRANSPORT

httpStream

httpStream or stdio

FASTMCP_PORT

3143

HTTP port (only for httpStream)

FASTMCP_HOST

0.0.0.0

Bind address (use 127.0.0.1 for local-only)

LOG_LEVEL

info

fatal, error, warn, info, debug, trace

LOG_DIR

./logs

Directory for log files

Example .env

IMAP_HOST=imap.gmail.com
IMAP_USER=you@gmail.com
IMAP_PASS=abcd efgh ijkl mnop
IMAP_PORT=993
IMAP_SECURE=true
IMAP_REJECT_UNAUTHORIZED=true

SMTP_HOST=smtp.gmail.com
SMTP_USER=you@gmail.com
SMTP_PASS=abcd efgh ijkl mnop
SMTP_PORT=465
SMTP_SECURE=true

FASTMCP_TRANSPORT=httpStream
FASTMCP_PORT=3143
FASTMCP_HOST=0.0.0.0

LOG_LEVEL=info
LOG_DIR=/var/log/imap-smtp-mcp

🚀 Usage

Once configured, just run:

imap-smtp-mcp
# [INFO] HTTP Stream listening on http://0.0.0.0:3143/mcp

With systemd

# /etc/systemd/system/imap-smtp-mcp.service
[Unit]
Description=IMAP/SMTP MCP Server
After=network.target

[Service]
Type=simple
User=imap-smtp
EnvironmentFile=/etc/imap-smtp-mcp.env
ExecStart=/usr/bin/node /opt/imap-smtp-mcp/dist/index.js
Restart=always
RestartSec=10
StandardOutput=append:/var/log/imap-smtp-mcp/mcp.log
StandardError=append:/var/log/imap-smtp-mcp/mcp.err.log

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now imap-smtp-mcp
systemctl status imap-smtp-mcp

With Docker

FROM node:20-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY dist ./dist
ENV NODE_ENV=production
EXPOSE 3143
CMD ["node", "dist/index.js"]
docker run -d --name imap-smtp-mcp \
  -p 3143:3143 \
  --env-file ./.env \
  imap-smtp-mcp:latest

As an MCP client (Claude Code, etc.)

{
  "mcpServers": {
    "mail": {
      "url": "http://localhost:3143/mcp"
    }
  }
}

For a remote server, replace localhost with the host:

{
  "mcpServers": {
    "mail": {
      "url": "http://localhost:3143/mcp"
    }
  }
}

As stdio (alternative)

If you prefer stdio transport (one process per session, e.g. for local desktop):

{
  "mcpServers": {
    "mail": {
      "command": "node",
      "args": ["/path/to/imap-smtp-mcp/dist/index.js"],
      "env": {
        "FASTMCP_TRANSPORT": "stdio",
        "IMAP_HOST": "imap.gmail.com",
        "IMAP_USER": "you@gmail.com",
        "IMAP_PASS": "..."
      }
    }
  }
}

🧰 Tools reference

server_info

Returns IMAP/SMTP server details and inbox counts.

{
  "user": "you@example.com",
  "imap": "imap.example.com:993",
  "smtp": "smtp.example.com:465",
  "inbox_total": 42,
  "inbox_unread": 7
}

list_mailboxes

Lists all mailboxes with message counts.

[
  { "name": "INBOX", "total": 42, "unread": 7 },
  { "name": "Sent", "total": 15, "unread": 0 },
  { "name": "Drafts", "total": 0, "unread": 0 }
]

list_emails

Lists emails in a mailbox.

Param

Type

Default

Description

mailbox

string

INBOX

Mailbox name

limit

number

20

Max results (1-500)

unread_only

boolean

false

Only return unread emails

[
  {
    "uid": 1234,
    "subject": "Hello",
    "from": "alice@example.com",
    "to": "you@example.com",
    "date": "2026-07-25T18:00:00.000Z",
    "flags": ["\\Seen"],
    "preview": "First 200 chars of body..."
  }
]

read_email

Reads a full email by UID.

Param

Type

Description

uid

number

Email UID (from list_emails)

mailbox

string

Mailbox name (default INBOX)

Returns the email with full body. body is parsed as text/plain from the MIME source.

search_emails

Searches emails by keyword (matches body text).

Param

Type

Default

Description

query

string

(required)

Keyword

mailbox

string

INBOX

Mailbox

limit

number

20

Max results

send_email

Sends an email via SMTP.

Param

Type

Description

to

string

Recipient address

subject

string

Subject line

body

string

Plain-text body

Returns { status: "sent", to, subject, messageId }.

mark_read

Marks an email as read or unread.

Param

Type

Default

Description

uid

number

(required)

Email UID

mailbox

string

INBOX

Mailbox

read

boolean

true

true=read, false=unread

delete_email

Marks an email as deleted and expunges it. Permanent.

Param

Type

Default

Description

uid

number

(required)

Email UID

mailbox

string

INBOX

Mailbox

📧 Provider notes

Gmail

  1. Enable 2FA on your Google account

  2. Create an app password

  3. Use the app password as IMAP_PASS / SMTP_PASS

IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true

Outlook / Microsoft 365 / Hotmail / Live

  1. Enable 2FA on your Microsoft account

  2. Create an app password via Microsoft account security

  3. IMAP_USER should be your full email address

IMAP_HOST=outlook.office365.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_SECURE=false    # STARTTLS, not implicit TLS

Apple iCloud / Apple Mail / me.com / mac.com

  1. Enable 2FA on your Apple Account

  2. Generate an app-specific password at appleid.apple.com → Sign-In and Security → App-Specific Passwords

  3. Use your full iCloud email and the app-specific password

IMAP_HOST=imap.mail.me.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.mail.me.com
SMTP_PORT=587
SMTP_SECURE=false    # STARTTLS

Fastmail

IMAP_HOST=imap.fastmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.fastmail.com
SMTP_PORT=465
SMTP_SECURE=true

ProtonMail Bridge

Run ProtonMail Bridge locally, then:

IMAP_HOST=127.0.0.1
IMAP_PORT=1143
IMAP_SECURE=false
SMTP_HOST=127.0.0.1
SMTP_PORT=1025
SMTP_SECURE=false
IMAP_USER=your-bridge-username
IMAP_PASS=your-bridge-password

Yahoo Mail / AOL

IMAP_HOST=imap.mail.yahoo.com
SMTP_HOST=smtp.mail.yahoo.com

Generate an app password in Yahoo Account Security.

Zoho Mail

IMAP_HOST=imap.zoho.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.zoho.com
SMTP_PORT=465
SMTP_SECURE=true

Self-hosted (Dovecot, Stalwart, Postfix, Mailcow, etc.)

For self-hosted mail servers with self-signed certificates:

IMAP_REJECT_UNAUTHORIZED=false
SMTP_REJECT_UNAUTHORIZED=false

For production with valid certificates (Let's Encrypt), set both to true.

🛠️ Development

Scripts

npm run build       # Compile TypeScript to dist/
npm run dev         # Watch mode with tsx
npm run lint        # ESLint
npm test            # Run unit tests (vitest)
npm run test:watch  # Tests in watch mode
npm run format      # Prettier

Project layout

src/
  index.ts         # Entry point
  config.ts        # Env loading + Zod validation
  logger.ts        # Pino logger setup
  mail-service.ts  # IMAP/SMTP operations
  tools.ts         # MCP tool definitions
tests/
  config.test.ts   # Config validation tests
  mail-service.test.ts  # MailService with mocks
  tools.test.ts    # Tool registration + dispatch
.github/
  workflows/
    ci.yml         # Lint + test + build on Node 18/20/22

Adding a new tool

  1. Add a method to MailService (in src/mail-service.ts).

  2. Register the tool in registerMailTools (in src/tools.ts).

  3. Add a test in tests/tools.test.ts.

🔒 Security

  • No secrets in code. All credentials come from environment variables.

  • Use app passwords, not account passwords, for Gmail/Outlook/Yahoo.

  • For production, set IMAP_REJECT_UNAUTHORIZED=true and SMTP_REJECT_UNAUTHORIZED=true with valid certificates.

  • Bind FASTMCP_HOST=127.0.0.1 if the MCP client runs on the same host.

  • For remote access, place behind a reverse proxy (nginx) with TLS.

📜 License

MIT — see LICENSE.

🤝 Contributing

Issues and pull requests welcome. Please run npm run lint && npm test before submitting.

Related MCP Connectors

  • Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.

  • Email inboxes for AI agents: send, receive, reply, search, and manage threaded email over MCP.

  • Your agent needs a mailbox of its own — to receive, thread, draft and send, with attachments, without borrowing your personal inbox or your company's SMTP. **What you can ask for** • "Create an inbox for this agent and tell me its address." • "Read the new messages in this thread and draft a reply." • "Send this message with the attachment and wait for the response." • "Search this inbox for everything from that domain." • "Show delivery metrics and the events on this inbox." **How to use it** Point any MCP client at https://mcp.aisa.one/mail/mcp and sign in with OAuth — there is no key to create or paste. 49 tools: create and delete inboxes, list and read messages, raw message bodies, attachments, threads, drafts and draft attachments, send and reply, message search, inbox events, metrics, and list entries — reads and writes. **Why this rather than the source** A real inbox an agent owns, rather than an SMTP credential it borrows from a human. **It is also a door to the rest** The same login reaches 26 sources and 580+ operations. Find the contact elsewhere in the catalogue, then write to them from here — without adding a second server. **What it costs** Finding and inspecting an operation is free. Running one is billed per call at API prices, with no seat and no monthly minimum, and every call takes max_price_usd so an agent cannot overspend by accident. **Where else it reaches** https://mcp.aisa.one/sales/mcp finds the person to write to.

  • Hosted email MCP for AI agents with inboxes, send/receive, memory, recovery, and credits.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A generic IMAP and SMTP MCP server that enables AI agents to interact with email accounts for reading, searching, and sending messages. It provides high-level tools for managing email workflows like daily digests and folder organization across any standard email provider.
    1
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Connects any IMAP/SMTP mailbox to AI agents via MCP, enabling email read, search, send, reply, and management through natural language.
    4 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    A self-hosted MCP server that unifies multiple IMAP/SMTP mailboxes into one agentic inbox, enabling agents to list, search, read, and send email through MCP tools.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    A self-hosted, multi-mailbox MCP server that exposes IMAP/SMTP operations as tools for AI agents, enabling email management like listing folders, reading, searching, sending, and moving messages via natural language.
    MIT