Email MCP Server

Email MCP Server

An MCP server that enables AI models to read, search, and send emails via IMAP and SMTP protocols. It supports various providers like Gmail and Outlook, allowing for tasks such as retrieving unread messages, searching by sender, and managing mailbox folders.

Category
Visit Server

README

Email MCP Server

Email MCP Server

An MCP (Model Context Protocol) server for reading and sending emails via IMAP/SMTP. This server exposes email operations as MCP tools that can be used by Claude and other AI models. Works with Gmail, Outlook, and any email provider that supports IMAP/SMTP.

Features

  • List Emails: Retrieve emails from any mailbox folder
  • Get Unread Emails: Fetch only unread messages
  • Search Emails: Search with IMAP search criteria (e.g., by sender, date, subject)
  • Get Emails from Sender: Retrieve all emails from a specific sender
  • Get Emails by Subject: Search by subject text
  • Send Emails: Compose and send emails via SMTP
  • List Folders: View all available mailbox folders
  • Get Email Details: Fetch complete details of a specific email

Prerequisites

  • Python 3.10 or higher
  • An email account (Gmail, Outlook, etc.) with IMAP/SMTP enabled

Quick Start

1. For Gmail Users

  1. Enable 2-Factor Authentication in your Gmail account: https://myaccount.google.com/security
  2. Generate an "App Password" for Mail: https://myaccount.google.com/apppasswords
  3. Use your Gmail address and the generated app password

2. For Other Email Providers

  • Outlook: Use your Microsoft account password (or create app password if 2FA enabled)
  • Yahoo: Generate an "App Password": https://login.yahoo.com/account/security
  • Other providers: Consult your provider's IMAP/SMTP documentation

3. Installation

# Clone or navigate to the server directory
cd gmail-server

# Install dependencies
pip install -r requirements.txt
# or
pip install -e .

4. Configuration

Create a .env file in the project directory:

Edit .env with your email credentials:

EMAIL_ADDRESS=your_email@gmail.com
EMAIL_PASSWORD=your_app_password_or_password

# Optional: Custom IMAP/SMTP servers
# IMAP_SERVER=imap.gmail.com
# SMTP_SERVER=smtp.gmail.com

5. Run the Server

python gmail_mcp_server.py

The server will start and be ready to use with Claude or other MCP clients.

Available Tools

list_emails

List emails from a folder.

Parameters:

  • max_results (int, default: 10): Number of emails to retrieve
  • unread_only (bool, default: false): Only return unread emails
  • folder (string, default: "INBOX"): Mailbox folder name

Example:

list_emails(max_results=20, unread_only=true, folder="INBOX")

get_unread_emails

Get unread emails from a folder.

Parameters:

  • max_results (int, default: 10): Number of unread emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder name

get_emails_from_sender

Get emails from a specific sender.

Parameters:

  • sender (string): Email address of the sender
  • max_results (int, default: 10): Number of emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder name

search_emails

Search emails using IMAP search criteria.

Parameters:

  • query (string): IMAP search query
  • max_results (int, default: 10): Maximum results to return
  • folder (string, default: "INBOX"): Mailbox folder to search

Query Examples:

  • UNSEEN - Unread messages
  • FROM "user@example.com" - Emails from specific sender
  • SUBJECT "invoice" - Emails with "invoice" in subject
  • FLAGGED - Starred/flagged emails
  • UNFLAGGED - Unstarred emails
  • ALL - All emails (default search)
  • BEFORE <date> - Emails before a date (e.g., BEFORE "1-Jan-2024")
  • SINCE <date> - Emails since a date
  • LARGER <bytes> - Emails larger than size

You can combine criteria: UNSEEN FROM "user@example.com" or SUBJECT "urgent" FLAGGED

get_emails_by_subject

Get emails by subject text.

Parameters:

  • subject (string): Subject text to search for
  • max_results (int, default: 10): Maximum emails to retrieve
  • folder (string, default: "INBOX"): Mailbox folder to search

send_email

Send an email.

Parameters:

  • recipient (string): Recipient email address
  • subject (string): Email subject
  • body (string): Email body text
  • html (bool, default: false): If true, body is treated as HTML

get_email_details

Get full details of a specific email.

Parameters:

  • message_id (string): Email ID from IMAP

list_folders

List all available mailbox folders.

Supported Email Providers

Gmail

  • IMAP Server: imap.gmail.com (port 993)
  • SMTP Server: smtp.gmail.com (port 587)
  • Requires: App Password (not your regular Gmail password)

Configuration

The server uses environment variables for configuration:

  • EMAIL_ADDRESS: Your email address (required)
  • EMAIL_PASSWORD: Your password or app password (required)
  • IMAP_SERVER: IMAP server address (default: imap.gmail.com)
  • SMTP_SERVER: SMTP server address (default: smtp.gmail.com)

Usage Example with Claude

You can use this MCP server with Claude by adding it to your Claude configuration. After setting up the server, it will be available as a tool set that Claude can use to read, search, and send emails.

Troubleshooting

"Authentication failed"

  • For Gmail: Make sure you're using an App Password, not your regular Gmail password
  • For other providers: Verify your password is correct
  • Make sure IMAP/SMTP is enabled in your email account settings

"Connection refused"

  • Check your IMAP/SMTP server addresses
  • Verify your email provider's IMAP/SMTP ports
  • Check if your firewall blocks these ports

"Certificate verification failed"

  • This usually happens with corporate firewalls
  • The server uses SSL certificates for secure connections

"No module named 'mcp'"

  • Run: pip install -r requirements.txt

Security Notes

  • Never commit .env file to version control
  • Never hardcode credentials in scripts
  • The server requires your email password - store it safely
  • Use app-specific passwords when available (Gmail, Yahoo, etc.)
  • The server only supports read-only access to IMAP unless you explicitly allow send

File Structure

gmail-server/
├── gmail_mcp_server.py      # Main MCP server implementation
├── gmail_client.py          # IMAP/SMTP email client wrapper
├── pyproject.toml           # Project configuration
├── requirements.txt         # Python dependencies
├── .env.example             # Example environment variables
├── .gitignore              # Git ignore rules
├── setup.py                # Setup validation script
├── mcp-config.json         # MCP configuration example
└── README.md               # This file

License

MIT License

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