Gmail发送技巧-MCP服务器
🚀 人工智能电子邮件发送技巧 支持模型上下文协议(MCP)
通过Gmail发送电子邮件,使用具有Markdown内容支持的应用密码身份验证,专为AI代理和MCP兼容应用程序设计。
✨ 特性
📧 核心电子邮件功能
- Gmail SMTP集成 -通过Gmail的安全SMTP服务器(端口587,TLS)发送电子邮件
- 应用密码验证 -使用Gmail应用程序密码进行安全身份验证
- 丰富的错误报告 -详细的成功/失败反馈,包括错误类型
- 输入验证 -全面的电子邮件和参数验证
📝 增强的Markdown支持(v1.1.0+)
- 高级Markdown转换 -带有扩展的完整markdown库支持(BSD许可证)
- 专业电子邮件样式 -具有响应式设计的电子邮件安全CSS
- 优雅的回退系统 -外部库不可用时的基本Markdown转换器
- 商业许可证合规性 -商业用途的BSD许可依赖项
- 电子邮件客户端兼容性 -为主要电子邮件客户端优化HTML
🤖 人工智能集成
- MCP兼容 -AI代理的完整模型上下文协议支持
- OpenAI函数调用 -与OpenAI函数调用标准兼容
- 技能框架 -独立和集成执行模式
🚀 快速开始
1.安装
# Clone the repository
git clone
cd mcp-server-gmail-send
# Run automated installation
chmod +x install.sh
./install.sh2.Gmail设置
- 启用双因素身份验证 在您的Gmail帐户中
- 生成应用程序密码:
- 转到Google帐户→ 安全→ 2-步骤验证→ 应用程序密码 - 选择“邮件”并生成密码 - 保存16个字符的密码(例如。, abcd efgh ijkl mnop)
3.克劳德桌面集成
# Copy configuration to Claude Desktop
cp claude_desktop_config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Restart Claude Desktop4.测试设置
# Test the MCP server
python3 mcp_server.py --test
# Run comprehensive tests
python3 test_gmail_skill.py📧 用法示例
增强的Markdown到HTML转换(v1.1.0+)
该技能现在支持使用专业电子邮件样式进行高级Markdown转换:
支持的Markdown功能
- 标头 (H1-H6)具有适当的层次结构
- 文本格式 -粗体、斜体、删除线
- 列表 -有序和无序嵌套
- 链接 -自动链接格式化
- 代码块 -语法高亮显示和内联代码
- 引用 -专业报价风格
- 表格 -响应式表格设计(带markdown库)
电子邮件样式功能
- 📱 响应式设计 -适应桌面和移动电子邮件客户端
- 🎨 专业CSS -干净、现代的电子邮件外观
- 📧 电子邮件客户端兼容性 -适用于Gmail、Outlook、Apple Mail等。
- 🔧 优雅的后退 -高级功能不可用时的基本转换
Markdown内容示例
# Project Status Report
## Executive Summary
The project is **on track** with key milestones achieved:
### Completed Tasks ✅
1. User authentication system
2. Database schema design
3. API endpoints implementation
### In Progress 🚧
- Front-end development
- Integration testing
- Performance optimization
> **Note**: All deliverables are meeting quality standards.
For technical details, see: [Project Documentation](https://example.com/docs)
def get_project_status(): return "Active"
This Markdown will be converted to professional HTML email format automatically.
Basic Email Sending
from gmail_send_skill import GmailSendSkill
from skill_compat import ExecutionContext
# Initialize
skill = GmailSendSkill()
ctx = ExecutionContext()
# Send email
result = skill.execute(ctx,
username="your.email@gmail.com",
app_password="abcd efgh ijkl mnop",
content="# Hello World!\n\nThis is a **test** email with *markdown*.",
to_email="recipient@example.com",
subject="Test Email from Skill"
)
print(f"Success: {result['success']}")通过人工智能代理(克劳德桌面)
只需问克劳德:
Can you send an email using the gmail_send function? I need to send:
- From: my.email@gmail.com
- To: colleague@company.com
- Subject: Project Update
- Content: A markdown report about our progress
I'll provide my app password when prompted.📊 函数架构
OpenAI函数调用格式
{
"name": "gmail_send",
"description": "Send email via Gmail using App Password authentication with Markdown support",
"parameters": {
"type": "object",
"properties": {
"username": {
"type": "string",
"description": "Gmail address for authentication"
},
"app_password": {
"type": "string",
"description": "16-character Gmail App Password"
},
"content": {
"type": "string",
"description": "Email content in Markdown format"
},
"to_email": {
"type": "string",
"description": "Recipient email address"
},
"subject": {
"type": "string",
"description": "Email subject line",
"default": "Email from Gmail Send Skill"
},
"from_name": {
"type": "string",
"description": "Display name for sender",
"default": null
}
},
"required": ["username", "app_password", "content", "to_email"]
}
}📋 项目结构
mcp-server-gmail-send/
├── 📄 gmail_send_skill.py # Main skill implementation
├── 🔧 skill_compat.py # Framework compatibility layer
├── 🖥️ mcp_server.py # MCP server with stdio transport
├── 📊 version.py # Version management
├── 🧪 test_gmail_skill.py # Comprehensive test suite
├── ⚙️ mcp_config.json # MCP client configuration
├── 🔌 claude_desktop_config.json # Claude Desktop integration
├── 📦 requirements.txt # Python dependencies
├── 🛠️ install.sh # Automated installation script
├── 📖 GMAIL_SEND_USAGE.md # Detailed usage guide
├── 🚀 MCP_DEPLOYMENT.md # MCP deployment instructions
└── 📝 README.md # This file🔧 配置
MCP服务器配置
更新路径 mcp_config.json:
{
"mcpServers": {
"gmail-send": {
"command": "python",
"args": ["/absolute/path/to/mcp_server.py"],
"env": {
"PYTHONPATH": "/absolute/path/to/project"
}
}
}
}Claude桌面配置
更新 claude_desktop_config.json 使用您的安装路径并复制到:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json
🧪 测试
自动化测试
# Run all tests
python3 test_gmail_skill.py
# Test specific components
python3 test_gmail_skill.py --test TestGmailSendSkill
# Verbose output
python3 test_gmail_skill.py --verbose手动测试
# Test skill directly
python3 gmail_send_skill.py
# Test MCP server
python3 mcp_server.py --test
# Check version and info
python3 version.py --info⚙️ 技术细节
依赖关系和许可
核心依赖关系(内置Python)
smtplib-SMTP电子邮件发送email.mime-电子邮件组成ssl-TLS加密json-配置处理re-用于回退转换的正则表达式
可选增强功能(商业友好型)
- 标记语言 库(BSD 3条款许可证)
- ✅ 允许商业使用 - ✅ 允许分发 - ✅ 允许修改 - 🔧 不可用时的优雅回退
系统要求
- Python 3.7+(测试到3.12)
- Gmail SMTP的互联网连接
- 启用2FA的Gmail帐户
建筑
Gmail Send Skill Architecture
├── gmail_send_skill.py # Core skill implementation
├── skill_compat.py # Framework compatibility layer
├── mcp_server.py # MCP Protocol server
└── version.py # Version management
HTML Conversion Pipeline:
Markdown Content → Advanced/Basic Converter → CSS Styling → Email HTML转换系统详细信息
高级模式(带markdown库)
- 完全支持CommonMark规范
- 扩展:表格、删除线、任务列表
- 专业语法高亮
- 高级表格渲染
回退模式(内置)
- 基于正则表达式的Markdown解析
- 核心元素支持(标题、列表、格式)
- 电子邮件安全HTML生成
- 保持专业CSS样式
📚 文档
🔒 安全
最佳实践
- ✅ 使用应用程序密码 -切勿使用常规Gmail密码
- ✅ 启用2FA -生成应用程序密码所需
- ✅ 安全存储 -从不将凭据提交到版本控制
- ✅ 输入验证 -所有参数在使用前都经过验证
- ✅ 错误处理 -敏感信息不会出现错误
支持的身份验证
- Gmail应用程序密码 (推荐)
- G套房/工作区 带有应用程序密码的帐户
- 双因素身份验证 必需的
📊 响应格式
成功响应
{
"success": true,
"function_name": "gmail_send",
"result": {
"message": "Email sent successfully to recipient@example.com",
"timestamp": "2026-02-14T10:30:00",
"from": "sender@gmail.com",
"to": "recipient@example.com",
"subject": "Email Subject"
}
}错误响应
{
"success": false,
"function_name": "gmail_send",
"error": {
"message": "Authentication failed. Please check your credentials.",
"type": "authentication_error",
"details": "SMTP Authentication Error: (535, 'Incorrect password')"
}
}🔄 版本信息
当前版本: 1.0.0 (2026-02-14)
# Check version
python3 version.py --version
# Full version info
python3 version.py --info
# View changelog
python3 version.py --changelog🛠️ 需求
系统要求
- Python 3.7+ (必填)
- 互联网连接 用于SMTP访问
- Gmail帐户 启用2FA
依赖项
- 内置Python库:
smtplib,email,json,logging - 可选的:
markdown>=3.4.0(用于丰富格式)
兼容性
- ✅ MCP协议 2024-11-05
- ✅ OpenAI函数调用 兼容的
- ✅ 克劳德桌面 整合
- ✅ 跨平台 (macOS、Linux、Windows)
🆘 故障排除
常见问题
身份验证错误
# Verify App Password format (16 characters)
# Check 2FA is enabled
# Generate new App Password模块导入错误
# Check Python path
export PYTHONPATH=/path/to/mcp-server-gmail-send
# Verify file permissions
chmod 644 gmail_send_skill.pyMCP连接问题
# Test MCP server
python3 mcp_server.py --test
# Check Claude Desktop logs
tail -f ~/Library/Logs/Claude/claude-desktop.log支持资源
🤝 贡献
- 分叉存储库
- 创建特征分支:
git checkout -b feature/amazing-feature - 提交更改:
git commit -m 'Add amazing feature' - 推送到分支:
git push origin feature/amazing-feature - 打开拉取请求
开发设置
# Clone for development
git clone
cd mcp-server-gmail-send
# Install development dependencies
pip3 install -r requirements.txt
pip3 install pytest pytest-asyncio # For testing
# Run tests
python3 test_gmail_skill.py
# Check code style
python3 -m flake8 gmail_send_skill.py� 版本历史记录
v1.1.0(2024-12-19)-增强的Markdown支持
- ✨ 高级Markdown转换 -带有扩展的完整markdown库支持
- 🎨 专业电子邮件样式 -电子邮件客户端的响应式CSS
- 🔧 优雅的回退系统 -外部库不可用时的基本转换器
- ⚖️ 商业许可证合规性 -BSD许可依赖项
- 📧 电子邮件客户端优化 -提高了跨平台的兼容性
- 🧪 增强测试 -全面的转换和造型测试
v1.0.0(2024-12-19)-初始版本
- 📧 Gmail SMTP集成 -通过Gmail安全发送电子邮件
- 🔐 应用密码验证 -安全的凭证处理
- 🤖 MCP协议支持 -完整模型上下文协议实现
- 📝 基本Markdown支持 -简单的标记到HTML转换
- ✅ 全面测试 -18个单元测试,边缘情况覆盖
- 🛠️ 本地开发工具 -配置模板和测试工具
�📄 许可证
本项目根据 许可证 文件。
第三方许可证合规性
- markdown库 (可选)-BSD 3条款许可证-允许商业使用
- Python标准库 -Python软件基础许可证
🙏 致谢
- 模型上下文协议 -用于标准化的AI代理集成
- OpenAI函数调用 -对于函数模式标准
- Gmail SMTP -可靠的电子邮件传递基础设施
- Python社区 -对于优秀的库和工具
- Markdown社区 -对于BSD许可的markdown处理库
______________________________________________________________________
专为人工智能驱动的应用而构建 🤖 | MCP兼容 🔌 | 生产就绪 🚀
*Gmail Send Skill v1.1.0-通过专业电子邮件样式增强Markdown转换* 通过gmail发送邮件。
