MCP Email Server with SendGrid
An MCP server that enables AI applications to send text, HTML, and template-based emails using SendGrid. It supports file attachments, CC/BCC recipients, and easy deployment via Python or Docker.
README
โ๏ธ MCP Email Server with SendGrid
A Model Context Protocol (MCP) server that provides email sending capabilities through SendGrid. This server enables AI applications like Claude Desktop, Langflow, and other MCP clients to send emails programmatically.
๐ Features
- ๐ง Basic Email Sending - Send text or HTML emails
- ๐จ Template Support - Use SendGrid dynamic templates
- ๐ File Attachments - Attach files to emails
- ๐ฅ CC/BCC Support - Send copies to multiple recipients
- ๐ณ Docker Ready - Containerized deployment
- ๐ Secure - Environment-based configuration
๐ Prerequisites
- Python 3.10 or higher
- SendGrid account and API key (Sign up here)
- Verified sender email address in SendGrid
- Docker (optional, for containerized deployment)
๐ ๏ธ Installation
Option 1: Local Python Setup
-
Clone or navigate to the repository:
cd d:\repos\mcp_mail -
Create and activate virtual environment:
python -m venv venv .\venv\Scripts\activate # Windows -
Install dependencies:
pip install -e . -
Configure environment variables:
copy .env.example .envEdit
.envand add your credentials:SENDGRID_API_KEY=your_actual_sendgrid_api_key DEFAULT_FROM_EMAIL=your-verified-email@example.com DEFAULT_FROM_NAME=Your Name
Option 2: Docker Deployment
-
Configure environment:
copy .env.example .env # Edit .env with your credentials -
Build and run with Docker Compose:
docker-compose up -dOr build manually:
docker build -t mcp-email-server . docker run --env-file .env mcp-email-server
๐ง Configuration
SendGrid Setup
-
Create a SendGrid account at sendgrid.com
-
Generate an API key:
- Go to Settings โ API Keys
- Click "Create API Key"
- Select "Full Access" or "Restricted Access" with Mail Send permissions
- Copy the API key (you'll only see it once!)
-
Verify sender email:
- Go to Settings โ Sender Authentication
- Verify the email address you'll use as the sender
- This is required by SendGrid to prevent spam
Environment Variables
| Variable | Required | Description |
|---|---|---|
SENDGRID_API_KEY |
Yes | Your SendGrid API key |
DEFAULT_FROM_EMAIL |
Yes | Default sender email (must be verified in SendGrid) |
DEFAULT_FROM_NAME |
No | Default sender name displayed to recipients |
๐ Usage
Running the Server
Local:
python server.py
Docker:
docker-compose up
The server communicates via stdio (standard input/output) using the MCP protocol.
Available MCP Tools
1. send_email
Send a basic email with text or HTML content.
Parameters:
to_email(required): Recipient email addresssubject(required): Email subject linebody(required): Email content (text or HTML)from_email(optional): Sender email (uses DEFAULT_FROM_EMAIL if not provided)from_name(optional): Sender namecc_emails(optional): List of CC recipientsbcc_emails(optional): List of BCC recipientsis_html(optional): Set to true for HTML emails (default: false)
Example:
{
"to_email": "recipient@example.com",
"subject": "Hello from MCP",
"body": "<h1>Welcome!</h1><p>This is a test email.</p>",
"is_html": true
}
2. send_email_with_template
Send an email using a SendGrid dynamic template.
Parameters:
to_email(required): Recipient email addresstemplate_id(required): SendGrid template IDdynamic_data(required): Dictionary of template variablesfrom_email(optional): Sender emailfrom_name(optional): Sender namesubject(optional): Override template subject
Example:
{
"to_email": "user@example.com",
"template_id": "d-1234567890abcdef",
"dynamic_data": {
"username": "John",
"action_url": "https://example.com/verify"
}
}
3. send_email_with_attachments
Send an email with file attachments.
Parameters:
to_email(required): Recipient email addresssubject(required): Email subject linebody(required): Email contentattachment_paths(required): List of file paths to attachfrom_email(optional): Sender emailfrom_name(optional): Sender nameis_html(optional): HTML email flag
Example:
{
"to_email": "recipient@example.com",
"subject": "Report Attached",
"body": "Please find the report attached.",
"attachment_paths": ["/path/to/report.pdf", "/path/to/data.csv"]
}
๐ Integration Examples
Claude Desktop
Add to your Claude Desktop config file (claude_desktop_config.json):
{
"mcpServers": {
"email": {
"command": "python",
"args": ["d:\\repos\\mcp_mail\\server.py"],
"env": {
"SENDGRID_API_KEY": "your_api_key",
"DEFAULT_FROM_EMAIL": "your-email@example.com",
"DEFAULT_FROM_NAME": "Your Name"
}
}
}
}
Or using Docker:
{
"mcpServers": {
"email": {
"command": "docker",
"args": ["run", "-i", "--rm", "--env-file", "d:\\repos\\mcp_mail\\.env", "mcp-email-server"]
}
}
}
Langflow Integration
- Install an MCP client component in Langflow (if available) or use a custom Python component
- Configure the MCP server connection with the email server's stdio transport
- Call the email tools from your Langflow flows
See examples/langflow_integration.md for detailed instructions.
Python Client Example
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="python",
args=["d:/repos/mcp_mail/server.py"],
env={
"SENDGRID_API_KEY": "your_key",
"DEFAULT_FROM_EMAIL": "your@email.com"
}
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Call the send_email tool
result = await session.call_tool("send_email", {
"to_email": "recipient@example.com",
"subject": "Test Email",
"body": "Hello from MCP!",
"is_html": False
})
print(result)
๐งช Testing
Run the test script to verify functionality:
python test_server.py
This will test the email sending functions with mocked SendGrid responses.
๐ Troubleshooting
"SendGrid client not initialized"
- Ensure
SENDGRID_API_KEYis set in your.envfile - Verify the API key is valid and has Mail Send permissions
"403 Forbidden" error
- Your sender email address must be verified in SendGrid
- Go to SendGrid Settings โ Sender Authentication
"No from_email provided"
- Set
DEFAULT_FROM_EMAILin your.envfile, or - Provide
from_emailparameter in each request
Attachments not working
- Ensure the file paths are absolute and accessible
- Check file permissions
- Verify files exist at the specified paths
๐ Resources
๐ License
MIT License - feel free to use this in your projects!
๐ค Contributing
Contributions welcome! Feel free to submit issues or pull requests.
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.