MCP server for IMAP/SMTP email operations
- PHP 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .devin/workflows | ||
| .forgejo/workflows | ||
| bin | ||
| classes/Mail | ||
| config | ||
| docs | ||
| includes | ||
| libraries | ||
| system | ||
| tests | ||
| tools | ||
| .gitignore | ||
| .gitleaksignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| phpunit.xml | ||
| README.md | ||
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, andpharextensions - 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.