Gmail-MCP-Server 是一个借助 fastMCP 构建的高弹性 MCP 服务器,可通过 Gmail 的 SMTP 服务器发送电子邮件,还能利用 AI 代理处理文件附件。
此仓库包含一个使用 fastMCP 构建的有弹性的 MCP 实现。该服务器旨在通过 Gmail 的 SMTP 服务器发送电子邮件,并支持以下几种方法来附加文件:
该服务器的设计注重弹性,具备增加的超时设置和优雅的关闭处理机制。
pip install mcp 安装)pip install python-dotenv 安装)pip install requests 安装)git clone <远程仓库 URL>
cd gmail-mcp-server
.env 文件,并添加您的 Gmail SMTP 资格凭证:SMTP_USERNAME=your.email@gmail.com
SMTP_PASSWORD=your_app_password
⚠️ 重要提示
如果您在 Gmail 账户上启用了两步验证,必须生成并使用应用程序密码。
{
"mcpServers": {
"gmail-mcp": {
"command": "python",
"args": ["PATH_TO_gmail-mcp.py"],
"port": 5005
}
}
}
将 PATH_TO_gmail-mcp.py 替换为实际的脚本路径。
pip install mcp
python your_script_name.py
在 Python 脚本中,直接从文件路径附加:
from mcp import Client
client = Client('localhost', 5005)
client.send_email_with_attachment('to@example.com', '主题', '正文', '/path/to/file.txt')
通过指定的 URL 下载并附加文件:
from mcp import Client
client = Client('localhost', 5005)
client.send_email_with_url_attachment('to@example.com', '主题', '正文', 'http://example.com/file.txt')
使用预存的附件进行处理:
from mcp import Client
client = Client('localhost', 5005)
client.send_email_with_pre_attached_file('to@example.com', '主题', '正文', '/path/to/pre_attachment.txt')