MCP server for IMAP/SMTP email operations
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
devin 37e5e8d5c9
All checks were successful
CI / behaviour-windows (push) Successful in 14s
CI / test (push) Successful in 16s
Merge pull request 'Fix SMTP session poisoning and empty-recipient sends' (#38) from fix/smtp-session-recovery into master
2026-11-07 17:51:50 -06:00
.devin/workflows release: v1.1.1 — add MCP tool annotations (readOnlyHint) 2026-06-30 19:01:13 -04:00
.forgejo/workflows chore: re-vendor libraries on the EnchiladaCurl split; CI runs the curl suite 2026-10-22 02:10:43 -04:00
bin Fix stdio stalls for hosts with broken or undrained pipes 2026-09-13 02:21:51 -04:00
classes/Mail Only RSET on fully-read rejections; disconnect on transport errors 2026-11-07 17:30:39 -05:00
config Fix From header using bare login username instead of valid addr-spec (#16) 2026-08-01 22:22:49 -04:00
docs chore: re-vendor libraries on the EnchiladaCurl split; CI runs the curl suite 2026-10-22 02:10:43 -04:00
includes Initial commit: Mail MCP Server v0.1.0 2026-05-08 03:24:05 -04:00
libraries chore: re-vendor libraries on the EnchiladaCurl split; CI runs the curl suite 2026-10-22 02:10:43 -04:00
system Release v1.4.0 2026-10-22 03:36:03 -04:00
tests Fix flaky testAppendLiteral: consume full APPEND literal in fake server 2026-11-07 17:53:27 -05:00
tools Fix SMTP session poisoning and empty-recipient sends 2026-11-07 17:06:11 -05:00
.gitignore release: v1.1.1 — add MCP tool annotations (readOnlyHint) 2026-06-30 19:01:13 -04:00
.gitleaksignore chore: release v1.0.1 2026-05-10 02:00:27 -04:00
CHANGELOG.md Release v1.4.0 2026-10-22 03:36:03 -04:00
LICENSE Initial commit: Mail MCP Server v0.1.0 2026-05-08 03:24:05 -04:00
phpunit.xml Add tests + CI/CD workflows 2026-05-08 04:37:51 -04:00
README.md Add mail_update_draft to modify existing drafts (#22) 2026-09-04 15:08:56 -04:00

SecureMessage Mail MCP Server

A PHP Model Context Protocol server for IMAP/SMTP email operations, built on the Enchilada Framework. Part of the SecureMessage project.

Uses pure PHP socket IMAP/SMTP clients — no ext-imap, no Composer, no Node.js. Zero external dependencies beyond PHP 8.4 with openssl, curl, iconv, ctype, and fileinfo.

Features

  • 22 tools — search, read, send, reply, drafts, attachments, threads, move, flags
  • Multi-account — manage multiple mail accounts, switchable at runtime
  • Unified search — single tool with 12+ filter parameters, multi-mailbox search across all folders
  • Drafts — create drafts for review before sending
  • Organization — move messages between folders, manage flags/labels
  • Threads — retrieve full conversation threads
  • OAuth/XOAUTH2 — Gmail, Microsoft 365, Yahoo via XOAUTH2 authentication
  • PHAR deployment — single-file distribution, no installation required
  • Built on the EnchiladaMCP library

Requirements

  • PHP 8.4+ with openssl, curl, iconv, ctype, fileinfo, and phar extensions
  • An IMAP/SMTP mail account (Gmail, Outlook, Fastmail, self-hosted, etc.)

Quick Start (PHAR)

Download the latest PHAR from Releases:

curl -LO https://pacyworld.dev/securemessage/mail-mcp/releases/download/v1.1.6/mail-mcp.phar
chmod +x mail-mcp.phar

Create a config file:

mkdir -p ~/.config/mail-mcp
cat > ~/.config/mail-mcp/instances.json << 'EOF'
{
    "default": "personal",
    "instances": {
        "personal": {
            "imap_host": "imap.example.com",
            "imap_port": 993,
            "smtp_host": "smtp.example.com",
            "smtp_port": 465,
            "username": "user@example.com",
            "password": "your-app-password",
            "tls": true
        }
    }
}
EOF

Start the server:

php mail-mcp.phar

For OAuth, multi-instance, and provider-specific settings, see docs/SETUP.md.

From Source

git clone https://pacyworld.dev/securemessage/mail-mcp.git
cd mail-mcp
cp config/instances.json.sample config/instances.json
# Edit config/instances.json with your mail server details
php bin/mail-mcp

AI Assistant Configuration

Windsurf / Cascade

Add to ~/.codeium/windsurf/mcp_config.json:

{
    "mail": {
        "command": "php",
        "args": ["/path/to/mail-mcp.phar"]
    }
}

Claude Code / Claude Desktop

{
    "mcpServers": {
        "mail": {
            "command": "php",
            "args": ["/path/to/mail-mcp.phar"]
        }
    }
}

To use a config file in a non-default location:

{
    "mail": {
        "command": "php",
        "args": ["/path/to/mail-mcp.phar"],
        "env": {
            "MAIL_MCP_CONFIG": "/path/to/instances.json"
        }
    }
}

Available Tools

Tool Description
mail_connect Connect to IMAP/SMTP for a mail account
mail_disconnect Disconnect from mail servers
mail_connection_status Show connection state for all accounts
mail_list_mailboxes List available folders
mail_open_mailbox Select a folder (returns message counts)
mail_create_mailbox Create a new folder
mail_search Search with flexible filters (from, to, cc, subject, body, date, flags, keywords)
mail_get_message Fetch single message with full content
mail_get_headers Fetch raw RFC 5322 headers, folding and repeats intact
mail_get_messages Fetch multiple messages (headers only)
mail_get_thread Retrieve full conversation thread
mail_delete_message Delete a message
mail_send Send a new email (with file attachments)
mail_reply Reply with quoted original message
mail_create_draft Save a draft for review before sending
mail_update_draft Modify an existing draft (recipients, subject, body, attachments)
mail_mark_read Mark message(s) as read
mail_mark_unread Mark message(s) as unread
mail_set_flags Add/remove IMAP flags and keywords
mail_move_message Move messages between folders
mail_get_attachments List attachment metadata
mail_save_attachment Save attachment to file or return as base64
mail_list_instances List configured accounts
mail_switch_instance Change default account

All tools accept an optional instance parameter to target a specific mail account.

Agent Skill

For AI-assisted setup, point your AI agent to the setup skill.

Documentation

  • docs/SETUP.md — Full setup guide (auth methods, providers, IDE integration, troubleshooting)
  • docs/OAUTH.md — OAuth setup for Gmail, Google Workspace, Microsoft 365
  • docs/TOOLS.md — Complete tool reference with all parameters
  • docs/AGENT_SKILL.md — Agent skill for AI-assisted installation

License

BSD 2-Clause — see LICENSE.