gmail-automation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGmail Automation via Rube MCP
通过Rube MCP实现Gmail自动化
Automate Gmail operations through Composio's Gmail toolkit via Rube MCP.
通过Composio的Gmail工具包,借助Rube MCP实现Gmail操作自动化。
Prerequisites
前提条件
- Rube MCP must be connected (RUBE_SEARCH_TOOLS available)
- Active Gmail connection via with toolkit
RUBE_MANAGE_CONNECTIONSgmail - Always call first to get current tool schemas
RUBE_SEARCH_TOOLS
- 必须已连接Rube MCP(需支持RUBE_SEARCH_TOOLS)
- 通过完成Gmail连接,工具包选择
RUBE_MANAGE_CONNECTIONSgmail - 请始终先调用获取最新的工具架构
RUBE_SEARCH_TOOLS
Setup
设置步骤
Get Rube MCP: Add as an MCP server in your client configuration. No API keys needed — just add the endpoint and it works.
https://rube.app/mcp- Verify Rube MCP is available by confirming responds
RUBE_SEARCH_TOOLS - Call with toolkit
RUBE_MANAGE_CONNECTIONSgmail - If connection is not ACTIVE, follow the returned auth link to complete Google OAuth
- Confirm connection status shows ACTIVE before running any workflows
获取Rube MCP:在客户端配置中添加作为MCP服务器。无需API密钥,只需添加端点即可使用。
https://rube.app/mcp- 确认可正常响应,以此验证Rube MCP是否可用
RUBE_SEARCH_TOOLS - 调用并指定工具包为
RUBE_MANAGE_CONNECTIONSgmail - 如果连接状态未显示为ACTIVE,请按照返回的授权链接完成Google OAuth认证
- 在运行任何工作流之前,确认连接状态已变为ACTIVE
Core Workflows
核心工作流
1. Send an Email
1. 发送邮件
When to use: User wants to compose and send a new email
Tool sequence:
- - Resolve contact name to email address [Optional]
GMAIL_SEARCH_PEOPLE - - Send the email [Required]
GMAIL_SEND_EMAIL
Key parameters:
- : Email address or 'me' for self
recipient_email - : Email subject line
subject - : Email content (plain text or HTML)
body - : Must be
is_htmlif body contains HTML markuptrue - /
cc: Arrays of email addressesbcc - : Object with
attachmentfrom prior download{s3key, mimetype, name}
Pitfalls:
- At least one of ,
recipient_email, orccrequiredbcc - At least one of or
subjectrequiredbody - Attachment MUST contain '/' (e.g., 'application/pdf', not 'pdf')
mimetype - Total message size limit ~25MB after base64 encoding
- Use only for verified aliases in Gmail 'Send mail as' settings
from_email
适用场景:用户需要撰写并发送新邮件
工具调用序列:
- - 将联系人姓名解析为邮箱地址(可选)
GMAIL_SEARCH_PEOPLE - - 发送邮件(必填)
GMAIL_SEND_EMAIL
关键参数:
- : 收件人邮箱地址,或填写'me'表示发送给自己
recipient_email - : 邮件主题
subject - : 邮件内容(纯文本或HTML格式)
body - : 如果内容包含HTML标记,必须设为
is_htmltrue - /
cc: 邮箱地址数组bcc - : 来自之前下载操作的对象,格式为
attachment{s3key, mimetype, name}
注意事项:
- 必须至少填写、
recipient_email或cc中的一项bcc - 必须至少填写或
subject中的一项body - 附件的必须包含'/'(例如:'application/pdf',不能只填'pdf')
mimetype - Base64编码后的邮件总大小限制约为25MB
- 仅当是Gmail“以其他身份发送”设置中已验证的别名时,才可使用该参数
from_email
2. Reply to a Thread
2. 回复邮件线程
When to use: User wants to reply to an existing email conversation
Tool sequence:
- - Find the email/thread to reply to [Prerequisite]
GMAIL_FETCH_EMAILS - - Send reply within the thread [Required]
GMAIL_REPLY_TO_THREAD
Key parameters:
- : Hex string from FETCH_EMAILS (e.g., '169eefc8138e68ca')
thread_id - : Reply content
message_body - : Reply recipient
recipient_email - : Set
is_htmlfor HTML contenttrue
Pitfalls:
- must be hex string; prefixes like 'msg-f:' are auto-stripped
thread_id - Legacy Gmail web UI IDs (e.g., 'FMfcgz...') are NOT supported
- Subject is inherited from original thread; setting it creates a new thread instead
- Do NOT include subject parameter to stay within thread
适用场景:用户需要回复现有邮件会话
工具调用序列:
- - 找到需要回复的邮件/线程(前提步骤)
GMAIL_FETCH_EMAILS - - 在该线程内发送回复(必填)
GMAIL_REPLY_TO_THREAD
关键参数:
- : 来自FETCH_EMAILS的十六进制字符串(例如:'169eefc8138e68ca')
thread_id - : 回复内容
message_body - : 回复收件人
recipient_email - : 若为HTML内容则设为
is_htmltrue
注意事项:
- 必须是十六进制字符串;类似'msg-f:'的前缀会被自动移除
thread_id - 不支持旧版Gmail网页端ID(例如:'FMfcgz...')
- 回复的主题会继承原线程的主题;若手动设置主题,将创建新的线程
- 请勿填写subject参数,以确保回复在原线程内
3. Search and Filter Emails
3. 搜索与筛选邮件
When to use: User wants to find specific emails by sender, subject, date, label, etc.
Tool sequence:
- - Search with Gmail query syntax [Required]
GMAIL_FETCH_EMAILS - - Get full message details for selected results [Optional]
GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID
Key parameters:
- : Gmail search syntax (from:, to:, subject:, is:unread, has:attachment, after:YYYY/MM/DD, before:YYYY/MM/DD)
query - : 1-500 messages per page
max_results - : System IDs like 'INBOX', 'UNREAD'
label_ids - : Set
include_payloadto get full message contenttrue - : Set
ids_onlyfor just message IDstrue - : For pagination (from
page_token)nextPageToken
Pitfalls:
- Returns max ~500 per page; follow via
nextPageTokenuntil absentpage_token - is approximate, not exact count
resultSizeEstimate - Use 'is:' for states (is:unread, is:snoozed, is:starred)
- Use 'label:' ONLY for user-created labels
- Common mistake: 'label:snoozed' is WRONG — use 'is:snoozed'
- on broad searches creates huge responses; default to metadata
include_payload=true - Custom labels require label ID (e.g., 'Label_123'), NOT label name
适用场景:用户需要按发件人、主题、日期、标签等条件查找特定邮件
工具调用序列:
- - 使用Gmail查询语法进行搜索(必填)
GMAIL_FETCH_EMAILS - - 获取选中邮件的完整详情(可选)
GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID
关键参数:
- : Gmail搜索语法(from:, to:, subject:, is:unread, has:attachment, after:YYYY/MM/DD, before:YYYY/MM/DD)
query - : 每页最多返回1-500条消息
max_results - : 系统标签ID,如'INBOX'、'UNREAD'
label_ids - : 设为
include_payload可获取完整邮件内容true - : 设为
ids_only仅返回邮件IDtrue - : 用于分页(来自返回结果的
page_token)nextPageToken
注意事项:
- 每页最多返回约500条结果;需通过传递
page_token,直到该字段不存在nextPageToken - 为近似值,并非精确计数
resultSizeEstimate - 状态类条件请使用'is:'(如is:unread, is:snoozed, is:starred)
- 'label:'仅适用于用户创建的标签
- 常见错误:使用'label:snoozed'是错误的,应使用'is:snoozed'
- 若在大范围搜索时设置,会产生极大的响应数据;默认应仅获取元数据
include_payload=true - 自定义标签需要使用标签ID(例如:'Label_123'),而非标签名称
4. Manage Labels
4. 管理标签
When to use: User wants to create, modify, or organize labels
Tool sequence:
- - List all labels to find IDs and detect conflicts [Required]
GMAIL_LIST_LABELS - - Create a new label [Optional]
GMAIL_CREATE_LABEL - - Rename or change label colors/visibility [Optional]
GMAIL_PATCH_LABEL - - Delete a user-created label (irreversible) [Optional]
GMAIL_DELETE_LABEL
Key parameters:
- : Max 225 chars, no commas, '/' for nesting (e.g., 'Work/Projects')
label_name - /
background_color: Hex values from Gmail's predefined palettetext_color - : Label ID for PATCH/DELETE operations
id
Pitfalls:
- 400/409 error if name is blank, duplicate, or reserved (INBOX, SPAM, CATEGORY_*)
- Color specs must use Gmail's predefined palette of 102 hex values
- DELETE is permanent and removes label from all messages
- Cannot delete system labels (INBOX, SENT, DRAFT, etc.)
适用场景:用户需要创建、修改或整理标签
工具调用序列:
- - 列出所有标签以获取ID并检测重名(必填)
GMAIL_LIST_LABELS - - 创建新标签(可选)
GMAIL_CREATE_LABEL - - 重命名标签或修改标签颜色/可见性(可选)
GMAIL_PATCH_LABEL - - 删除用户创建的标签(操作不可逆)(可选)
GMAIL_DELETE_LABEL
关键参数:
- : 最多225个字符,不能包含逗号,可用'/'表示嵌套(例如:'Work/Projects')
label_name - /
background_color: Gmail预定义调色板中的十六进制值text_color - : 用于PATCH/DELETE操作的标签ID
id
注意事项:
- 若标签名称为空、重复或为保留名称(INBOX、SPAM、CATEGORY_*),会返回400/409错误
- 颜色设置必须使用Gmail预定义的102种十六进制值
- DELETE操作是永久的,会将标签从所有邮件中移除
- 无法删除系统标签(INBOX、SENT、DRAFT等)
5. Apply/Remove Labels on Messages
5. 为邮件添加/移除标签
When to use: User wants to label, archive, or mark emails as read/unread
Tool sequence:
- - Get label IDs for custom labels [Prerequisite]
GMAIL_LIST_LABELS - - Find target messages [Prerequisite]
GMAIL_FETCH_EMAILS - - Bulk add/remove labels (up to 1000 messages) [Required]
GMAIL_BATCH_MODIFY_MESSAGES - - Single-message label changes [Fallback]
GMAIL_ADD_LABEL_TO_EMAIL
Key parameters:
- : Array of message IDs (max 1000)
messageIds - : Array of label IDs to add
addLabelIds - : Array of label IDs to remove
removeLabelIds - : 15-16 char hex string for single operations
message_id
Pitfalls:
- Max 1000 messageIds per BATCH call; chunk larger sets
- Use 'CATEGORY_UPDATES' not 'UPDATES'; full prefix required for category labels
- SENT, DRAFT, CHAT are immutable — cannot be added/removed
- To mark as read: REMOVE 'UNREAD'. To archive: REMOVE 'INBOX'
- must be 15-16 char hex, NOT UUIDs or web UI IDs
message_id
适用场景:用户需要为邮件添加标签、归档或标记为已读/未读
工具调用序列:
- - 获取自定义标签的ID(前提步骤)
GMAIL_LIST_LABELS - - 找到目标邮件(前提步骤)
GMAIL_FETCH_EMAILS - - 批量添加/移除标签(最多支持1000封邮件)(必填)
GMAIL_BATCH_MODIFY_MESSAGES - - 为单封邮件修改标签(备选方案)
GMAIL_ADD_LABEL_TO_EMAIL
关键参数:
- : 邮件ID数组(最多1000个)
messageIds - : 要添加的标签ID数组
addLabelIds - : 要移除的标签ID数组
removeLabelIds - : 单封邮件操作时使用的15-16位十六进制字符串
message_id
注意事项:
- 每次BATCH调用最多支持1000个messageIds;数量更多时需分批处理
- 分类标签需使用完整前缀,例如'CATEGORY_UPDATES'而非'UPDATES'
- SENT、DRAFT、CHAT标签为不可变标签,无法添加或移除
- 标记为已读:移除'UNREAD'标签;归档:移除'INBOX'标签
- 必须是15-16位十六进制字符串,不能是UUID或网页端ID
message_id
6. Handle Drafts and Attachments
6. 处理草稿与附件
When to use: User wants to create, edit, or send email drafts, possibly with attachments
Tool sequence:
- - Create a new draft [Required]
GMAIL_CREATE_EMAIL_DRAFT - - Edit draft content [Optional]
GMAIL_UPDATE_DRAFT - - List existing drafts [Optional]
GMAIL_LIST_DRAFTS - - Send a draft (requires explicit user approval) [Optional]
GMAIL_SEND_DRAFT - - Download attachment from existing message [Optional]
GMAIL_GET_ATTACHMENT
Key parameters:
- : Draft recipient
recipient_email - : Draft subject (omit for reply drafts to stay in thread)
subject - : Draft content
body - : Set
is_htmlfor HTML contenttrue - : Object with
attachment{s3key, mimetype, name} - : For reply drafts (leave subject empty to stay in thread)
thread_id
Pitfalls:
- Response includes (draft_id) AND
data.id; usedata.message.idfor draft operationsdata.id - Setting subject on a thread reply draft creates a NEW thread instead
- Attachment capped at ~25MB; base64 overhead can push near-limit files over
- UPDATE_DRAFT replaces entire content, not patches; include all fields you want to keep
- HTTP 429 on bulk draft creation; use exponential backoff
适用场景:用户需要创建、编辑或发送邮件草稿,或处理附件
工具调用序列:
- - 创建新草稿(必填)
GMAIL_CREATE_EMAIL_DRAFT - - 编辑草稿内容(可选)
GMAIL_UPDATE_DRAFT - - 列出所有现有草稿(可选)
GMAIL_LIST_DRAFTS - - 发送草稿(需要用户明确授权)(可选)
GMAIL_SEND_DRAFT - - 从现有邮件中下载附件(可选)
GMAIL_GET_ATTACHMENT
关键参数:
- : 草稿收件人
recipient_email - : 草稿主题(回复线程的草稿请留空,以保持在原线程内)
subject - : 草稿内容
body - : 若为HTML内容则设为
is_htmltrue - : 格式为
attachment的对象{s3key, mimetype, name} - : 回复线程的草稿使用(留空subject以保持在原线程内)
thread_id
注意事项:
- 响应结果包含(draft_id)和
data.id;草稿操作请使用data.message.iddata.id - 若为线程回复草稿设置主题,将创建新的线程
- 附件大小上限约为25MB;Base64编码的额外开销可能会使接近上限的文件超出限制
- UPDATE_DRAFT会替换草稿的全部内容,而非局部修改;请包含所有需要保留的字段
- 批量创建草稿可能触发HTTP 429错误;请实现指数退避策略
Common Patterns
通用模式
ID Resolution
ID解析
Label name → Label ID:
1. Call GMAIL_LIST_LABELS
2. Find label by name in response
3. Extract id field (e.g., 'Label_123')Contact name → Email:
1. Call GMAIL_SEARCH_PEOPLE with query=contact_name
2. Extract emailAddresses from responseThread ID from search:
1. Call GMAIL_FETCH_EMAILS or GMAIL_LIST_THREADS
2. Extract threadId (15-16 char hex string)标签名称 → 标签ID:
1. 调用GMAIL_LIST_LABELS
2. 在响应结果中按名称查找标签
3. 提取id字段(例如:'Label_123')联系人姓名 → 邮箱地址:
1. 调用GMAIL_SEARCH_PEOPLE,参数query=contact_name
2. 从响应结果中提取emailAddresses字段从搜索结果中获取线程ID:
1. 调用GMAIL_FETCH_EMAILS或GMAIL_LIST_THREADS
2. 提取threadId(15-16位十六进制字符串)Pagination
分页处理
- Set up to 500 per page
max_results - Check response for
nextPageToken - Pass token as in next request
page_token - Continue until is absent or empty string
nextPageToken - is approximate, not exact
resultSizeEstimate
- 设置最多为每页500条
max_results - 检查响应结果中的
nextPageToken - 在下次请求中传递该token作为参数
page_token - 持续请求直到不存在或为空字符串
nextPageToken - 为近似值,并非精确计数
resultSizeEstimate
Gmail Query Syntax
Gmail查询语法
Operators:
- - Emails from sender
from:sender@example.com - - Emails to recipient
to:recipient@example.com - - Subject contains exact phrase
subject:"exact phrase" - - Unread messages
is:unread - - Starred messages
is:starred - - Snoozed messages
is:snoozed - - Has attachments
has:attachment - - After date (YYYY/MM/DD)
after:2024/01/01 - - Before date
before:2024/12/31 - - User-created label (use label ID)
label:custom_label - - In sent folder
in:sent - - Primary category
category:primary
Combinators:
- - Both conditions (default)
AND - - Either condition
OR - - Exclude condition
NOT - - Group conditions
()
Examples:
- - Unread emails from boss
from:boss@company.com is:unread - - Invoices with attachments this year
subject:invoice has:attachment after:2024/01/01 - - Starred emails from Alice or Bob
(from:alice OR from:bob) is:starred
操作符:
- - 来自指定发件人的邮件
from:sender@example.com - - 发送给指定收件人的邮件
to:recipient@example.com - - 主题包含指定精确短语的邮件
subject:"exact phrase" - - 未读邮件
is:unread - - 已加星标的邮件
is:starred - - 已延后的邮件
is:snoozed - - 包含附件的邮件
has:attachment - - 指定日期之后的邮件(格式YYYY/MM/DD)
after:2024/01/01 - - 指定日期之前的邮件
before:2024/12/31 - - 带有指定用户自定义标签的邮件(需使用标签ID)
label:custom_label - - 已发送文件夹中的邮件
in:sent - - 主要分类的邮件
category:primary
组合符:
- - 同时满足两个条件(默认逻辑)
AND - - 满足任一条件
OR - - 排除满足条件的邮件
NOT - - 对条件进行分组
()
示例:
- - 来自老板的未读邮件
from:boss@company.com is:unread - - 今年的带附件的发票邮件
subject:invoice has:attachment after:2024/01/01 - - 来自Alice或Bob的已加星标邮件
(from:alice OR from:bob) is:starred
Known Pitfalls
已知注意事项
ID Formats:
- Custom label operations require label IDs (e.g., 'Label_123'), not display names
- Always call LIST_LABELS first to resolve names to IDs
- Message IDs are 15-16 char hex strings
- Do NOT use UUIDs, web UI IDs, or 'thread-f:' prefixes
Query Syntax:
- Use 'is:' for states (unread, snoozed, starred)
- Use 'label:' ONLY for user-created labels
- System labels use 'is:' or 'in:' (e.g., 'is:sent', 'in:inbox')
Rate Limits:
- BATCH_MODIFY_MESSAGES max 1000 messages per call
- Heavy use triggers 403/429 rate limits
- Implement exponential backoff for bulk operations
Response Parsing:
- Response data may be nested under or
data_previewdata.messages - Parse defensively with fallbacks
- Timestamp uses RFC3339 with 'Z' suffix
messageTimestamp - Normalize to '+00:00' for parsing if needed
Attachments:
- Attachment from prior download may expire
s3key - Use promptly after retrieval
- Mimetype must include '/' separator
ID格式:
- 自定义标签操作需要使用标签ID(例如:'Label_123'),而非显示名称
- 请始终先调用LIST_LABELS将名称解析为ID
- 邮件ID是15-16位十六进制字符串
- 请勿使用UUID、网页端ID或'thread-f:'前缀
查询语法:
- 状态类条件请使用'is:'(unread, snoozed, starred)
- 'label:'仅适用于用户创建的标签
- 系统标签请使用'is:'或'in:'(例如:'is:sent', 'in:inbox')
速率限制:
- BATCH_MODIFY_MESSAGES每次调用最多支持1000封邮件
- 高频使用会触发403/429速率限制
- 批量操作请实现指数退避策略
响应解析:
- 响应数据可能嵌套在或
data_preview下data.messages - 请使用防御式解析并设置回退逻辑
- 时间戳采用带'Z'后缀的RFC3339格式
messageTimestamp - 若需要,可将其标准化为'+00:00'格式进行解析
附件:
- 从之前下载操作获取的附件可能会过期
s3key - 请在获取后尽快使用
- Mimetype必须包含'/'分隔符
Quick Reference
快速参考
| Task | Tool Slug | Key Params |
|---|---|---|
| Send email | GMAIL_SEND_EMAIL | recipient_email, subject, body, is_html |
| Reply to thread | GMAIL_REPLY_TO_THREAD | thread_id, message_body, recipient_email |
| Search emails | GMAIL_FETCH_EMAILS | query, max_results, label_ids, page_token |
| Get message details | GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID | message_id |
| List labels | GMAIL_LIST_LABELS | (none) |
| Create label | GMAIL_CREATE_LABEL | label_name, background_color, text_color |
| Modify labels bulk | GMAIL_BATCH_MODIFY_MESSAGES | messageIds, addLabelIds, removeLabelIds |
| Create draft | GMAIL_CREATE_EMAIL_DRAFT | recipient_email, subject, body, thread_id |
| Send draft | GMAIL_SEND_DRAFT | draft_id |
| Get attachment | GMAIL_GET_ATTACHMENT | message_id, attachment_id |
| Search contacts | GMAIL_SEARCH_PEOPLE | query |
| Get profile | GMAIL_GET_PROFILE | (none) |
| 任务 | 工具标识 | 关键参数 |
|---|---|---|
| 发送邮件 | GMAIL_SEND_EMAIL | recipient_email, subject, body, is_html |
| 回复线程 | GMAIL_REPLY_TO_THREAD | thread_id, message_body, recipient_email |
| 搜索邮件 | GMAIL_FETCH_EMAILS | query, max_results, label_ids, page_token |
| 获取邮件详情 | GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID | message_id |
| 列出标签 | GMAIL_LIST_LABELS | 无 |
| 创建标签 | GMAIL_CREATE_LABEL | label_name, background_color, text_color |
| 批量修改标签 | GMAIL_BATCH_MODIFY_MESSAGES | messageIds, addLabelIds, removeLabelIds |
| 创建草稿 | GMAIL_CREATE_EMAIL_DRAFT | recipient_email, subject, body, thread_id |
| 发送草稿 | GMAIL_SEND_DRAFT | draft_id |
| 获取附件 | GMAIL_GET_ATTACHMENT | message_id, attachment_id |
| 搜索联系人 | GMAIL_SEARCH_PEOPLE | query |
| 获取个人资料 | GMAIL_GET_PROFILE | 无 |