Email (IMAP/SMTP) logo

Email (IMAP/SMTP)

Community
yunfeizhu

A lightweight Model Context Protocol (MCP) server that provides IMAP and SMTP email functionality for AI assistants like Claude in Cursor IDE. Built with TypeScript and optimized for easy deployment via npm/npx.

Publisheryunfeizhu
Repositorymcp-mail-server
LanguageTypeScript
Forks
15
Stars
31
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    Email (IMAP/SMTP) exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    31 stars and 15 forks from the linked repository.

MCP Mail Server

NPM Version License: MIT

Language: English | 中文

A Model Context Protocol server for IMAP/SMTP email operations with Claude, Cursor, and other AI assistants.

Features

  • IMAP Operations: Search, read, and manage emails across mailboxes
  • SMTP Support: Send emails with HTML/text content and attachments
  • Attachment Management: View attachment metadata and save attachments to local files
  • Secure Configuration: Environment-based setup with TLS/SSL support
  • AI-Friendly: Natural language commands for email operations
  • Auto Connection Management: Automatic IMAP/SMTP connection handling
  • Multi-Mailbox Support: Access INBOX, Sent, and custom folders

Changelog

[1.2.1] - 2026-03-18

Fixed

  • Fixed search criteria (FROM/TO/SUBJECT/BODY/KEYWORD/SINCE) not using nested array format, causing errors on TO and other searches
  • Fixed search() wrapping criteria in an extra array, breaking compound search conditions
  • Fixed deleteMessage() failing silently when the mailbox was opened in read-only mode
  • Fixed getRecentMessages() misusing the IMAP RECENT flag; now fetches latest N messages by UID
  • Fixed getRecentMessages() / getUnseenMessages() relying on leftover mailbox state from previous operations
  • Fixed cleanReplySubject() only stripping one Re: prefix layer, causing false negatives in unreplied detection
  • Fixed email date stored as locale string causing inconsistent new Date() parsing across platforms; changed to ISO 8601
  • Fixed ensureIMAPConnection() having no timeout while waiting for concurrent initialization
  • Fixed saveSentMessage() always returning sentFolderSaved: true even when save failed
  • Fixed handleGetMessages() / handleDeleteMessage() relying on currentBox state to locate messages
  • Fixed reply_to_email writing literal "undefined" into the body when text is empty

Added

  • All search tools now support an inboxOnly parameter to restrict search to INBOX only

Improved

  • ensureSMTPConnection() now has concurrency guard with 30-second timeout, consistent with IMAP
  • Sent mailbox auto-detected via RFC 6154 \Sent special-use attribute with result caching, compatible with all mail providers
  • saveMessageToFolder() simplified; skips saving if no sent folder is found
  • Search now uses slice(-limit) to fetch the newest messages first, preventing empty results after date filtering
  • HTML-escape applied to quoted content in reply emails to prevent XSS injection

For the full version history, see CHANGELOG.md.


Quick Start

  1. Install: npm install -g mcp-mail-server
  2. Configure environment variables (see Configuration)
  3. Add to your MCP client configuration
  4. Use natural language: "Show me unread emails from today"

Installation

Add to your claude_desktop_config.json:

json
{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": ["-y", "mcp-mail-server"],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Add to your Cursor MCP settings:

json
{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": ["-y", "mcp-mail-server"],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Add using the claude mcp add command:

bash
claude mcp add mcp-mail-server \
  -e IMAP_HOST=your-imap-server.com \
  -e IMAP_PORT=993 \
  -e IMAP_SECURE=true \
  -e SMTP_HOST=your-smtp-server.com \
  -e SMTP_PORT=465 \
  -e SMTP_SECURE=true \
  -e EMAIL_USER=your-email@domain.com \
  -e EMAIL_PASS=your-password \
  -- npx -y mcp-mail-server

Or manually add to .claude/settings.json:

json
{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": ["-y", "mcp-mail-server"],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Add to codex.json in your project root:

json
{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": ["-y", "mcp-mail-server"],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Other MCP clients can be configured similarly. The core configuration is:

json
{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": ["-y", "mcp-mail-server"],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Refer to your specific client's documentation for the appropriate configuration file location.

Available Tools

ToolDescription
connect_allConnect to both IMAP and SMTP servers
get_connection_statusCheck connection status and server info
disconnect_allDisconnect from all servers
open_mailboxOpen specific mailbox/folder
list_mailboxesList available mail folders
get_message_countGet total message count in current mailbox
get_unseen_messagesGet all unread emails
get_recent_messagesGet recent emails
search_by_senderFind emails from specific sender
search_by_subjectSearch by subject keywords
search_by_recipientFind emails sent to specific recipient
search_by_bodySearch message body content
search_since_dateFind emails since date
search_unread_from_senderFind unread emails from specific sender
search_unreplied_from_senderFind unreplied emails from specific sender
search_with_keywordSearch emails by keyword/flag
search_all_messagesSearch all messages with optional date range and limit
get_messageRetrieve email by UID
get_messagesRetrieve multiple emails
delete_messageDelete email by UID
send_emailSend email via SMTP (with optional attachments)
reply_to_emailReply to specific email
get_attachmentsGet attachment metadata for an email
save_attachmentDownload and save attachments to local files

Connection Management

  • connect_all: No parameters required
  • get_connection_status: No parameters required
  • disconnect_all: No parameters required

Mailbox Operations

  • open_mailbox: mailboxName (string, default: "INBOX"), readOnly (boolean)
  • list_mailboxes: No parameters required

Search Operations

  • search_by_sender: sender (string, email address), startDate (string, optional), endDate (string, optional)
  • search_by_subject: subject (string, keywords), startDate (string, optional), endDate (string, optional)
  • search_by_recipient: recipient (string, email address), startDate (string, optional), endDate (string, optional)
  • search_by_body: text (string, search text), startDate (string, optional), endDate (string, optional)
  • search_since_date: date (string, date format)
  • search_unread_from_sender: sender (string, email address), startDate (string, optional), endDate (string, optional)
  • search_unreplied_from_sender: sender (string, email address), startDate (string, optional), endDate (string, optional), limit (number, optional)
  • search_with_keyword: keyword (string, keyword), startDate (string, optional), endDate (string, optional)
  • search_all_messages: startDate (string, optional), endDate (string, optional), limit (number, optional, default: 50)

Message Operations

  • get_message_count: No parameters required
  • get_unseen_messages: No parameters required
  • get_recent_messages: No parameters required
  • get_message: uid (number), markSeen (boolean, optional)
  • get_messages: uids (array), markSeen (boolean, optional)
  • delete_message: uid (number)

Email Sending

  • send_email: to (string), subject (string), text (string, optional), html (string, optional), cc (string, optional), bcc (string, optional), attachments (string[], optional, absolute file paths)
  • reply_to_email: originalUid (number), text (string), html (string, optional), replyToAll (boolean, optional), includeOriginal (boolean, optional)

Attachment Operations

  • get_attachments: uid (number) — Returns metadata: filename, contentType, size, index
  • save_attachment: uid (number), savePath (string, absolute path), attachmentIndex (number, optional, 0-based), returnBase64 (boolean, optional, default: false)

Usage Examples

Use natural language commands with your AI assistant:

Basic Operations

  • "Connect to my email servers"
  • "Show me all unread emails"
  • "Search for emails from boss@company.com"
  • "Send an email to team@company.com about the meeting"
  • "Reply to email with UID 123"

Advanced Searches

  • "Find emails with 'urgent' in the subject from last week"
  • "Show me unreplied emails from boss@company.com"
  • "Search emails sent to team@company.com"
  • "Get all emails from the Sales folder"
  • "Show unread emails from boss@company.com"
  • "Show me all emails from the last 7 days"
  • "List all messages, limit to 20"

Email Management

  • "Delete the email with UID 123"
  • "Mark recent emails as read"
  • "List all my email folders"

Attachment Operations

  • "Show me the attachments of email UID 456"
  • "Save all attachments from email UID 456 to D:/Downloads"
  • "Download the first attachment from email UID 789"
  • "Send an email to team@company.com with attachment D:/report.pdf"

Configuration

Environment Variables

⚠️ All variables are required

VariableDescriptionExample
IMAP_HOSTIMAP server addressimap.gmail.com
IMAP_PORTIMAP port number993
IMAP_SECUREEnable TLStrue
SMTP_HOSTSMTP server addresssmtp.gmail.com
SMTP_PORTSMTP port number465
SMTP_SECUREEnable SSLtrue
EMAIL_USEREmail usernameyour-email@gmail.com
EMAIL_PASSEmail password/app passwordyour-app-password

Common Email Providers

bash
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password

Note: Use App Passwords instead of your regular password.

bash
IMAP_HOST=outlook.office365.com
IMAP_PORT=993
IMAP_SECURE=true
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_SECURE=true
EMAIL_USER=your-email@outlook.com
EMAIL_PASS=your-password

Security Notes

  • Use App Passwords: Enable 2FA and use app-specific passwords when available
  • TLS/SSL Required: Always use secure connections (IMAP_SECURE=true, SMTP_SECURE=true)
  • Environment Variables: Never hardcode credentials in configuration files

Development

  1. Clone the repository:

    bash
    git clone https://github.com/yunfeizhu/mcp-mail-server.git
    cd mcp-mail-server
  2. Install dependencies:

    bash
    npm install
  3. Build the project:

    bash
    npm run build
  4. Set environment variables:

    bash
    export IMAP_HOST=your-imap-server.com
    export IMAP_PORT=993
    export IMAP_SECURE=true
    export SMTP_HOST=your-smtp-server.com
    export SMTP_PORT=465
    export SMTP_SECURE=true
    export EMAIL_USER=your-email@domain.com
    export EMAIL_PASS=your-password
  5. Run the server:

    bash
    npm start

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.


Package Information:

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "mcp-mail-server": {
      "command": "npx",
      "args": [
        "mcp-mail-server"
      ],
      "env": {
        "IMAP_HOST": "your-imap-server.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "SMTP_HOST": "your-smtp-server.com",
        "SMTP_PORT": "465",
        "SMTP_SECURE": "true",
        "EMAIL_USER": "your-email@domain.com",
        "EMAIL_PASS": "your-password"
      }
    }
  }
}

Use Email (IMAP/SMTP) MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Email (IMAP/SMTP) is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add Email (IMAP/SMTP) as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the Email (IMAP/SMTP) MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "email-imap-smtp": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mail-server"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the Email (IMAP/SMTP) MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the Email (IMAP/SMTP) MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Email (IMAP/SMTP) to help me with this task?
Email (IMAP/SMTP)
Sure. I read it.
Here is what I found using Email (IMAP/SMTP).

Frequently asked questions

What is the Email (IMAP/SMTP) MCP server used for?

Email (IMAP/SMTP) is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Email (IMAP/SMTP) MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Email (IMAP/SMTP) with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Email (IMAP/SMTP) MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Email (IMAP/SMTP) connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Email (IMAP/SMTP) MCP to TypingMind?

Email (IMAP/SMTP) runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does Email (IMAP/SMTP) MCP provide in TypingMind?

Email (IMAP/SMTP) exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Email (IMAP/SMTP) MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Email (IMAP/SMTP) requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇