feishu-cli-mail
Installation
SKILL.md
飞书邮箱(Mail)
查看、发送、回复、转发邮件,管理草稿,过滤收件箱。
首期限制:
send / draft-create / draft-edit / reply / reply-all / forward仅支持纯文本/HTML body,暂不支持附件和 CID 内联图片。
前置条件
- 认证:所有 mail 命令都需要 User Access Token(执行
feishu-cli auth login登录) - 预检:
feishu-cli auth check --scope "mail:user_mailbox:readonly"可验证 scope
命令速查
查询类命令(只读)
| 命令 | 用途 |
|---|---|
mail message |
获取单封邮件(含 HTML 或纯文本 body) |
mail messages |
批量获取多封邮件 |
mail thread |
获取邮件线程(对话) |
mail triage |
列出/过滤邮件(folder/label/query/unread-only) |
# 查未读收件箱
feishu-cli mail triage --folder INBOX --unread-only --page-size 20
# 列出可用文件夹和标签
feishu-cli mail triage --list-folders
feishu-cli mail triage --list-labels
# 搜索邮件
feishu-cli mail triage --query "周会"
# 获取单封
feishu-cli mail message --message-id msg_xxx
feishu-cli mail message --message-id msg_xxx --format plain_text_full
# 批量获取
feishu-cli mail messages --message-ids m1,m2,m3
# 获取线程
feishu-cli mail thread --thread-id thread_xxx
写入类命令
| 命令 | 用途 |
|---|---|
mail send |
发送邮件(默认草稿,加 --confirm-send 立即发送) |
mail draft-create |
创建草稿(不发送) |
mail draft-edit |
编辑已有草稿(全量覆盖) |
mail reply |
回复邮件(自动 Re: 前缀 + 引用块 + In-Reply-To) |
mail reply-all |
全部回复(包含原邮件 To 和 CC 的所有人,自动排除自己) |
mail forward |
转发邮件(自动 Fwd: 前缀 + 原文) |
# 发邮件(默认保存为草稿,安全兜底)
feishu-cli mail send --to user@example.com --subject "测试" --body "hi"
# 直接发送
feishu-cli mail send --to user@example.com --subject "测试" --body "hi" --confirm-send
# 多人、抄送、HTML
feishu-cli mail send --to a@x.com,b@x.com --cc c@x.com \
--subject "会议纪要" --body "<h2>议程</h2><p>1. ...</p>" --html --confirm-send
# 创建草稿
feishu-cli mail draft-create --to user@example.com --subject "草稿" --body "初稿"
# 编辑草稿
feishu-cli mail draft-edit --draft-id xxx --to user@example.com --subject "修订" --body "新内容"
# 回复
feishu-cli mail reply --message-id msg_xxx --body "收到,周三开会"
feishu-cli mail reply --message-id msg_xxx --body "同意" --confirm-send
# 全部回复
feishu-cli mail reply-all --message-id msg_xxx --body "+1"
# 转发
feishu-cli mail forward --message-id msg_xxx --to new@example.com --body "请关注此邮件"
典型工作流
处理未读邮件
# 1. 查未读
feishu-cli mail triage --folder INBOX --unread-only -o json > unread.json
# 2. 逐封处理(拿 message_id → 看内容 → 回复)
feishu-cli mail message --message-id <id> -o json
feishu-cli mail reply --message-id <id> --body "已阅" --confirm-send
发送 HTML 邮件
feishu-cli mail send \
--to team@example.com \
--subject "周报" \
--body "$(cat weekly-report.html)" \
--html \
--confirm-send
草稿审阅工作流
# 1. 创建草稿
DRAFT_ID=$(feishu-cli mail draft-create --to user@example.com --subject "合同" --body "初稿" -o json | jq -r .draft_id)
# 2. 审阅后修改
feishu-cli mail draft-edit --draft-id $DRAFT_ID --to user@example.com --subject "合同 v2" --body "修订后内容"
# 3. 通过 mail send 重建为真发送(draft-edit 只更新不发送)
# 或在飞书 Web 上手动发送
权限要求
| 命令 | 必需 scope |
|---|---|
mail message/messages/thread/triage |
mail:user_mailbox:readonly、mail:user_mailbox.message:readonly、mail:user_mailbox.message.body:read、mail:user_mailbox.message.address:read、mail:user_mailbox.message.subject:read |
mail send/draft-create/draft-edit/reply/reply-all/forward |
上述只读权限 + mail:user_mailbox.message:send、mail:user_mailbox.message:modify |
注意事项
- 默认草稿:
mail send默认只保存草稿(安全兜底)。必须显式加--confirm-send才会真正发送邮件。 - HTML 自动检测:如果
--body含以下任一标签自动按 HTML 发送:<html>/<body>/<div>/<p>/<br>/<b>/<i>/<a/<table>/<h1>/<h2>/<h3>。可用--plain-text或--html强制指定。 - 引用块:
reply/reply-all会自动把原邮件 body 作为>引用块附加到回复正文后。 - 发件人识别:不传
--from时,从 mailbox profile(GET /profile)自动读取primary_email_address和name。 - EML 格式:所有发送命令底层都构造 RFC 5322 格式 EML,经过 base64 URL-safe 编码后提交给
/draftsAPI。 - Mailbox 定位:
--mailbox默认me(当前登录用户),也可以传具体邮箱地址(前提是当前 Token 有权限)。 - subject 去重:
reply自动避免Re: Re:重复;forward自动避免Fwd: Fwd:重复。 - In-Reply-To / References:
reply/reply-all自动从原邮件的smtp_message_id/references继承,确保邮件客户端正确展示对话线程。 - 附件 / CID 图片暂不支持:首期 EML builder 是简化版。如需附件,请在 feishu Web 手动处理或等后续迭代。
- 批量 messages 上限:取决于飞书 API 端;本命令不做数量校验,但通常建议 ≤50 条。