关于 gmail
gmail 是通过独立 OAuth 认证操作 Gmail 的轻量级技能,面向 Google Workspace 用户。它涵盖邮件搜索、收发、草稿和标签管理,且无需 MCP 服务。
主要功能
- 01独立 OAuth 登录与令牌管理
- 02按 Gmail 查询语法搜索邮件
- 03读取邮件内容或元数据
- 04发送邮件并管理草稿
- 05修改邮件标签及查看标签列表
适用场景
- 01筛选未读或带附件的邮件
- 02查看邮件正文或邮件头信息
- 03撰写邮件、发送草稿或整理标签
MCP 相关
该技能使用独立 OAuth 认证和命令行脚本操作 Gmail,不需要 MCP 服务。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ sanjay3290/ ai-skills --skill gmail安装后在 Claude Code 中输入/gmail确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.mdrequirements.txtscripts/auth.pygmail.pyrequirements.txt详细介绍
Gmail
轻量级 Gmail 集成,使用独立的 OAuth 身份验证。无需 MCP 服务。
⚠️ 需要 Google Workspace 账号。 不支持个人 Gmail 账号。
首次设置
通过 Google 进行身份验证(打开浏览器):
python scripts/auth.py login
检查身份验证状态:
python scripts/auth.py status
需要时退出登录:
python scripts/auth.py logout
命令
所有操作均通过 scripts/gmail.py 执行。首次使用时,如果尚未登录,会自动进行身份验证。
搜索邮件
# Search with Gmail query syntax
python scripts/gmail.py search "from:[email protected] is:unread"
# Search recent emails (no query returns all)
python scripts/gmail.py search --limit 20
# Filter by label
python scripts/gmail.py search --label INBOX --limit 10
# Include spam and trash
python scripts/gmail.py search "subject:important" --include-spam-trash
阅读邮件内容
# Get full message content
python scripts/gmail.py get MESSAGE_ID
# Get just metadata (headers)
python scripts/gmail.py get MESSAGE_ID --format metadata
# Get minimal response (IDs only)
python scripts/gmail.py get MESSAGE_ID --format minimal
发送邮件
# Send a simple email
python scripts/gmail.py send --to "[email protected]" --subject "Hello" --body "Message body"
# Send with CC and BCC
python scripts/gmail.py send --to "[email protected]" --cc "[email protected]" --bcc "[email protected]" \
--subject "Team Update" --body "Update message"
# Send from an alias (must be configured in Gmail settings)
python scripts/gmail.py send --to "[email protected]" --subject "Hello" --body "Message" \
--from "Mile9 Accounts <[email protected]>"
# Send HTML email
python scripts/gmail.py send --to "[email protected]" --subject "HTML Email" \
--body "<h1>Hello</h1><p>HTML content</p>" --html
草稿管理
# Create a draft
python scripts/gmail.py create-draft --to "[email protected]" --subject "Draft Subject" \
--body "Draft content"
# Send an existing draft
python scripts/gmail.py send-draft DRAFT_ID
修改邮件(标签)
# Mark as read (remove UNREAD label)
python scripts/gmail.py modify MESSAGE_ID --remove-label UNREAD
# Mark as unread
python scripts/gmail.py modify MESSAGE_ID --add-label UNREAD
# Archive (remove from INBOX)
python scripts/gmail.py modify MESSAGE_ID --remove-label INBOX
# Star a message
python scripts/gmail.py modify MESSAGE_ID --add-label STARRED
# Unstar a message
python scripts/gmail.py modify MESSAGE_ID --remove-label STARRED
# Mark as important
python scripts/gmail.py modify MESSAGE_ID --add-label IMPORTANT
# Multiple label changes at once
python scripts/gmail.py modify MESSAGE_ID --remove-label UNREAD --add-label STARRED
列出标签
# List all Gmail labels (system and user-created)
python scripts/gmail.py list-labels
Gmail 查询语法
Gmail 支持强大的搜索运算符:
| 查询 | 说明 |
|---|---|
from:[email protected] | 来自特定发件人的邮件 |
to:[email protected] | 发给特定收件人的邮件 |
subject:meeting | 主题中包含“meeting”的邮件 |
is:unread | 未读邮件 |
is:starred | 已加星标的邮件 |
is:important | 重要邮件 |
has:attachment | 带附件的邮件 |
after:2024/01/01 | 指定日期之后的邮件 |
before:2024/12/31 | 指定日期之前的邮件 |
newer_than:7d | 最近 7 天内的邮件 |
older_than:1m | 1 个月以前的邮件 |
label:work | 带有特定标签的邮件 |
in:inbox | 收件箱中的邮件 |
in:sent | 已发送邮件 |
in:trash | 垃圾箱中的邮件 |
可使用 AND(空格)、OR 或 -(NOT)组合:
python scripts/gmail.py search "from:[email protected] is:unread newer_than:1d"
python scripts/gmail.py search "subject:urgent OR subject:important"
python scripts/gmail.py search "from:[email protected] -is:starred"
常用标签 ID
| 标签 | ID |
|---|---|
| 收件箱 | INBOX |
| 已发送 | SENT |
| 草稿 | DRAFT |
| 垃圾邮件 | SPAM |
| 垃圾箱 | TRASH |
| 已加星标 | STARRED |
| 重要 | IMPORTANT |
| 未读 | UNREAD |
令牌管理
令牌使用系统密钥环安全存储:
- macOS:钥匙串
- Windows:Windows 凭据保险库
- Linux:Secret Service API(GNOME Keyring、KDE Wallet 等)
服务名称:gmail-skill-oauth
令牌过期时,会通过 Google 的云函数自动刷新。
评论
支持 Markdown