关于 gmail
gmail 是一组基于 Node.js 的 Gmail 命令行脚本,适用于需要从命令行管理邮件的用户。它支持多个命名账户,并涵盖邮件搜索、读写、草稿和标签操作。
主要功能
- 01链接和管理多个账户
- 02按 Gmail 查询语法搜索邮件
- 03读取单封邮件或完整会话
- 04发送、回复并附加文件
- 05创建、发送和删除草稿
- 06管理标签及邮件状态
适用场景
- 01查找未读或带附件的邮件
- 02读取邮件会话并撰写回复
- 03从命令行发送带附件的邮件
- 04归档邮件或调整标签
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ blink-new/ claude --skill gmail安装后在 Claude Code 中输入/gmail确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
.gitignorepackage.jsonscripts/_client.mjs_mime.mjsaccounts.mjsauth.mjsdraft.mjslabel.mjslist.mjsread.mjsreply.mjssearch.mjssend.mjs详细介绍
Gmail
所有脚本都位于 ~/.cursor/skills/gmail/scripts/。可从任意位置运行。
账号管理
# List linked accounts
node accounts.mjs --list
# Link an account (runs browser OAuth flow)
node accounts.mjs --link # links as "default"
node accounts.mjs --link --account=work # links as named account
# Unlink an account
node accounts.mjs --unlink --account=work
账号存储:
~/.cursor/skills/gmail/
├── credentials.json # shared OAuth2 client (one for all accounts)
└── accounts/
├── default/
│ ├── token.json # access + refresh tokens ← SENSITIVE
│ └── profile.json # cached email address
└── work/
├── token.json
└── profile.json
所有脚本都接受 --account=<name>(默认值:default)
一次性设置
# 1. Get credentials.json from Google Cloud Console:
# console.cloud.google.com → Gmail API → Credentials → OAuth Client ID → Desktop App → Download JSON
mv ~/Downloads/client_secret_*.json ~/.cursor/skills/gmail/credentials.json
# 2. Link your first account
node ~/.cursor/skills/gmail/scripts/accounts.mjs --link
脚本
list.mjs
node list.mjs [--account=work] [--max=50] [--label=UNREAD] [--next-page=<token>]
search.mjs
node search.mjs --query="from:stripe" [--account=work] [--max=20] [--next-page=<token>]
# Gmail query syntax: from: to: subject: is:unread has:attachment after:2026/03/01
read.mjs
node read.mjs --id=<messageId> [--account=work] # single message
node read.mjs --id=<threadId> --thread [--account=work] # full thread
node read.mjs --id=<messageId> --raw # show raw HTML
reply.mjs
node reply.mjs --message-id=<id> --body="Text" [--account=work]
node reply.mjs --message-id=<id> --html="<b>Hi</b>"
node reply.mjs --message-id=<id> --body="Hi" --cc="[email protected]" --bcc="[email protected]"
node reply.mjs --message-id=<id> --body="See attached" --attachments="/path/a.pdf"
send.mjs
node send.mjs --to="[email protected]" --subject="Hi" --body="Text" [--account=work]
node send.mjs --to="[email protected]" --subject="Hi" --html="<h1>Hello</h1>"
node send.mjs --to="[email protected]" --subject="Hi" --body="Hi" --cc="[email protected]" --bcc="[email protected]"
node send.mjs --to="[email protected]" --subject="Files" --body="See attached" --attachments="/path/a.pdf,/path/b.png"
label.mjs
node label.mjs --list [--account=work]
node label.mjs --id=<messageId> --mark-read [--account=work]
node label.mjs --id=<messageId> --mark-unread
node label.mjs --id=<messageId> --archive
node label.mjs --id=<messageId> --trash
node label.mjs --id=<messageId> --star / --unstar
node label.mjs --id=<messageId> --add-label=IMPORTANT
node label.mjs --id=<messageId> --remove-label=SPAM
draft.mjs
node draft.mjs --list [--account=work]
node draft.mjs --create --to="[email protected]" --subject="Hi" --body="Text"
node draft.mjs --create --reply-to=<messageId> --body="Reply" # To: auto-filled
node draft.mjs --read --id=<draftId>
node draft.mjs --send --id=<draftId>
node draft.mjs --delete --id=<draftId>
滥用举报工作流
node search.mjs --query="from:namecheap subject:abuse"
node read.mjs --id=<messageId> --thread
node reply.mjs --message-id=<id> --body="Dear Namecheap Legal & Abuse Team,
Thank you for your message regarding ticket <TICKET-ID>.
We have completed our investigation and taken the following actions:
1. The account in question has been permanently suspended.
2. The reported URL (hxxp:// <PROJECT-ID> [.] sites [.] blink [.] new/) has been deactivated and now returns an HTTP 410 response.
3. All content and deployments associated with this account have been removed.
Our platform has a strict Acceptable Use Policy and we act promptly on all reports.
The blink.new domain is fully compliant with your Terms of Service.
Please let us know if anything further is needed to close this case.
Best regards,
Kai Feng
CEO, Blink.new
[email protected]"
云端设置
echo "GMAIL_CREDENTIALS=$(base64 -i ~/.cursor/skills/gmail/credentials.json)"
echo "GMAIL_TOKEN=$(base64 -i ~/.cursor/skills/gmail/accounts/default/token.json)"
在云容器中将其设为机密。脚本会优先检测环境变量而非文件(仅限默认账号)。
安全
credentials.json和token.json文件已加入 gitignore,绝不会离开你的设备- 要撤销访问权限:访问 https://myaccount.google.com/permissions → 找到你的应用 → 撤销
评论
支持 Markdown