Secure Gmail Skill (Composio-backed)
Provides read-only + draft Gmail access through Composio's managed authentication layer. OAuth tokens never touch your local filesystem or agent memory — Composio brokers every API call on its backend.
When to Use This Skill
Activate this skill when the user says any of the following:
- - "Check my emails" / "What's in my inbox?"
- "Did [person] reply?" / "Find emails from [sender]"
- "Summarize unread emails from today/this week"
- "Draft a reply to [email]" — creates draft, does NOT send
- "What did [person] send me about [topic]?"
- "Search for emails about [subject]"
Do NOT activate for:
- - "Send an email" → use a human-approved send skill
- "Delete emails" → blocked at API level, will fail gracefully
- "Access Google Drive or Calendar" → use /gog or /google-drive skill
Prerequisites (must be done before first use)
- 1. Composio account at app.composio.dev (free tier works)
- Gmail connected under Connected Accounts in Composio dashboard
- COMPOSIOAPIKEY set in ~/clawd/skills/secure-gmail/.env
- Python packages installed: INLINECODE0
If COMPOSIOAPIKEY is missing the skill will exit with:
Error: COMPOSIO_API_KEY not found in environment
Direct the user to add it to the .env file before retrying.
Exact Commands
Fetch recent emails
CODEBLOCK0
Search by sender
CODEBLOCK1
Search by subject keyword
CODEBLOCK2
Read a specific email
CODEBLOCK3
Create a draft reply
CODEBLOCK4
What Each Action Does Internally
| User Request | Composio Action Called | Result |
|---|
| Check inbox | GMAILFETCHEMAILS | Returns last N emails with sender, subject, date |
| Find email |
GMAIL
SEARCHMESSAGES | Returns matching threads |
| Read email | GMAIL
FETCHMESSAGE
BYMESSAGE_ID | Returns full email body |
| Draft reply | GMAIL
CREATEEMAIL_DRAFT | Creates draft, confirms saved not sent |
| Profile check | GMAIL
GETPROFILE | Returns authenticated email address |
Blocked Actions (Composio rejects these at gateway)
The following are not in the allowed list and are rejected before reaching Gmail — even if the agent tries to call them due to hallucination or ambiguous instructions:
- - GMAILSENDEMAIL
- GMAILDELETEMESSAGE
- GMAILMODIFYLABELS
- GMAILEMPTYTRASH
If a user asks to send or delete, respond:
"This skill is read and draft only. To send, please review the draft in Gmail and send it yourself, or install a send-enabled skill with human approval confirmation."
Output Format
The agent returns JSON. Parse and present it like this:
For email list:
CODEBLOCK5
For drafts:
CODEBLOCK6
Error Handling
| Error | Cause | Fix |
|---|
| INLINECODE2 | Missing .env key | Add key to .env file |
| INLINECODE3 |
OAuth not completed | Go to app.composio.dev → Connected Accounts |
|
Token expired | OAuth needs refresh | Reconnect Gmail in Composio dashboard |
|
Action not permitted | Tried blocked action | Expected — tell user it's read/draft only |
|
Rate limit exceeded | Too many requests | Wait 60 seconds and retry |
Security Architecture
This skill uses Composio's brokered authentication model:
- 1. User connects Gmail via OAuth at app.composio.dev
- Composio stores accesstoken and refreshtoken in encrypted vault
- OpenClaw receives only a connectedaccountid reference
- Every API call goes: OpenClaw → Composio → Gmail
- Raw credentials never enter agent memory or local filesystem
- Every call is logged in Composio dashboard with timestamp and action
- Access revocable instantly via Composio dashboard kill switch
This protects against three attack vectors:
- - Prompt injection stealing .env credentials (token not local)
- Context window leaks exposing OAuth tokens (token not in memory)
- Malicious skills reading credential files (nothing to read)
Audit Your Agent
After running, check app.composio.dev → Logs to see:
- - Exact timestamp of every Gmail action
- Which action was called (fetch, search, draft)
- Whether it succeeded or was blocked
- No action goes unrecorded
name: secure-gmail
description: Read emails, search inbox, and create drafts using Composio managed authentication. Use when user asks to check emails, read mail, search inbox, or draft replies. CANNOT send or delete emails (least privilege enforced by Composio).
metadata:
moltbot:
requires:
bins: ["python3"]
env: ["COMPOSIO
APIKEY"]
Secure Gmail Skill
Gmail access via Composio brokered auth.
The agent never sees your raw OAuth tokens.
Secure Gmail 技能(基于 Composio)
通过 Composio 的托管认证层提供只读 + 草稿模式的 Gmail 访问。OAuth 令牌永远不会触及您的本地文件系统或代理内存——Composio 在其后端代理每一个 API 调用。
何时使用此技能
当用户说出以下任何内容时,激活此技能:
- - 查看我的邮件 / 我的收件箱里有什么?
- [某人]回复了吗? / 查找来自[发件人]的邮件
- 总结今天/本周的未读邮件
- 草拟对[邮件]的回复——创建草稿,不会发送
- [某人]给我发了关于[主题]的什么内容?
- 搜索关于[主题]的邮件
不要为以下情况激活:
- - 发送邮件 → 使用人工批准的发送技能
- 删除邮件 → 在 API 层面被阻止,会优雅地失败
- 访问 Google Drive 或日历 → 使用 /gog 或 /google-drive 技能
前提条件(首次使用前必须完成)
- 1. 在 app.composio.dev 注册 Composio 账户(免费版可用)
- 在 Composio 控制台的已连接账户下连接 Gmail
- 在 ~/clawd/skills/secure-gmail/.env 中设置 COMPOSIOAPIKEY
- 安装 Python 包:pip install python-dotenv composio
如果缺少 COMPOSIOAPIKEY,技能将退出并显示:
错误:环境中未找到 COMPOSIOAPIKEY
请指导用户在重试前将其添加到 .env 文件中。
精确命令
获取最近的邮件
bash
cd ~/clawd/skills/secure-gmail && python3 agent.py 获取最近10封邮件
按发件人搜索
bash
python3 agent.py 查找本周来自 sarah@example.com 的邮件
按主题关键词搜索
bash
python3 agent.py 查找关于季度预算的邮件
读取特定邮件
bash
python3 agent.py 读取 ID 为 MESSAGE
IDHERE 的邮件
创建草稿回复
bash
python3 agent.py 草拟对 John 最后一封邮件的回复,说我会在周五前审阅
每个操作在内部执行的内容
| 用户请求 | 调用的 Composio 操作 | 结果 |
|---|
| 查看收件箱 | GMAILFETCHEMAILS | 返回最近 N 封邮件,包含发件人、主题、日期 |
| 查找邮件 |
GMAIL
SEARCHMESSAGES | 返回匹配的邮件线程 |
| 读取邮件 | GMAIL
FETCHMESSAGE
BYMESSAGE_ID | 返回完整的邮件正文 |
| 草拟回复 | GMAIL
CREATEEMAIL_DRAFT | 创建草稿,确认已保存但未发送 |
| 查看个人资料 | GMAIL
GETPROFILE | 返回已认证的电子邮件地址 |
被阻止的操作(Composio 在网关层拒绝)
以下操作不在允许列表中,在到达 Gmail 之前就会被拒绝——即使代理因幻觉或模糊指令尝试调用它们:
- - GMAILSENDEMAIL
- GMAILDELETEMESSAGE
- GMAILMODIFYLABELS
- GMAILEMPTYTRASH
如果用户要求发送或删除,请回复:
此技能仅支持读取和草稿模式。如需发送,请在 Gmail 中审阅草稿并自行发送,或安装带有审批确认的发送技能。
输出格式
代理返回 JSON。请按如下方式解析和呈现:
对于邮件列表:
📬 找到 5 封邮件:
- 1. 发件人:sarah@co.com | 主题:Q4 预算 | 日期:3月1日
- 发件人:mike@co.com | 主题:会议记录 | 日期:2月28日
...
对于草稿:
✅ 草稿已保存(未发送):
收件人:john@example.com
主题:Re:项目更新
预览:你好 John,我会在周五前审阅...
在以下位置查看:mail.google.com/mail/#drafts
错误处理
| 错误 | 原因 | 修复方法 |
|---|
| 未找到 COMPOSIOAPIKEY | 缺少 .env 密钥 | 将密钥添加到 .env 文件 |
| Gmail 未连接 |
OAuth 未完成 | 前往 app.composio.dev → 已连接账户 |
| 令牌已过期 | OAuth 需要刷新 | 在 Composio 控制台重新连接 Gmail |
| 操作不被允许 | 尝试了被阻止的操作 | 预期行为——告知用户仅支持读取/草稿 |
| 超出速率限制 | 请求过多 | 等待 60 秒后重试 |
安全架构
此技能使用 Composio 的代理认证模型:
- 1. 用户在 app.composio.dev 通过 OAuth 连接 Gmail
- Composio 将 accesstoken 和 refreshtoken 存储在加密保险库中
- OpenClaw 仅接收一个 connectedaccountid 引用
- 每个 API 调用的路径:OpenClaw → Composio → Gmail
- 原始凭据永远不会进入代理内存或本地文件系统
- 每个调用都在 Composio 控制台中记录时间戳和操作
- 可通过 Composio 控制台的终止开关立即撤销访问权限
这可以防范三种攻击向量:
- - 提示注入窃取 .env 凭据(令牌不在本地)
- 上下文窗口泄露暴露 OAuth 令牌(令牌不在内存中)
- 恶意技能读取凭据文件(无文件可读)
审计您的代理
运行后,查看 app.composio.dev → 日志以查看:
- - 每个 Gmail 操作的确切时间戳
- 调用了哪个操作(获取、搜索、草稿)
- 操作成功还是被阻止
- 所有操作均有记录
名称:secure-gmail
描述:使用 Composio 托管认证读取邮件、搜索收件箱和创建草稿。当用户要求查看邮件、阅读邮件、搜索收件箱或草拟回复时使用。无法发送或删除邮件(Composio 强制执行最小权限原则)。
元数据:
moltbot:
要求:
二进制文件:[python3]
环境变量:[COMPOSIO
APIKEY]
Secure Gmail 技能
通过 Composio 代理认证的 Gmail 访问。
代理永远不会看到您的原始 OAuth 令牌。