Rei-skills gmail-automation
Automate Gmail tasks via Rube MCP (Composio): send/reply, search, labels, drafts, attachments. Always search tools first for current schemas.
git clone https://github.com/rootcastleco/rei-skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/rootcastleco/rei-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/gmail-automation" ~/.claude/skills/rootcastleco-rei-skills-gmail-automation && rm -rf "$T"
skills/gmail-automation/SKILL.md⚠️ AUTHORIZED USE ONLY — This skill is intended for authorized security professionals only. Use only against systems you own or have explicit written permission to test. Unauthorized use may violate applicable laws.
Gmail Automation via Rube MCP
Automate Gmail operations through Composio's Gmail toolkit via Rube MCP.
Prerequisites
- Rube MCP must be connected (RUBE_SEARCH_TOOLS available)
- Active Gmail connection via
with toolkitRUBE_MANAGE_CONNECTIONSgmail - Always call
first to get current tool schemasRUBE_SEARCH_TOOLS
Setup
Get Rube MCP: Add
https://rube.app/mcp as an MCP server in your client configuration. No API keys needed — just add the endpoint and it works.
- Verify Rube MCP is available by confirming
respondsRUBE_SEARCH_TOOLS - Call
with toolkitRUBE_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
Core Workflows
1. Send an Email
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 selfrecipient_email
: Email subject linesubject
: Email content (plain text or HTML)body
: Must beis_html
if body contains HTML markuptrue
/cc
: Arrays of email addressesbcc
: Object withattachment
from prior download{s3key, mimetype, name}
Pitfalls:
- At least one of
,recipient_email
, orcc
requiredbcc - At least one of
orsubject
requiredbody - 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' settingsfrom_email
2. Reply to a Thread
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 contentmessage_body
: Reply recipientrecipient_email
: Setis_html
for HTML contenttrue
Pitfalls:
must be hex string; prefixes like 'msg-f:' are auto-strippedthread_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
3. Search and Filter Emails
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 pagemax_results
: System IDs like 'INBOX', 'UNREAD'label_ids
: Setinclude_payload
to get full message contenttrue
: Setids_only
for just message IDstrue
: For pagination (frompage_token
)nextPageToken
Pitfalls:
- Returns max ~500 per page; follow
vianextPageToken
until absentpage_token
is approximate, not exact countresultSizeEstimate- 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 metadatainclude_payload=true- Custom labels require label ID (e.g., 'Label_123'), NOT label name
4. Manage Labels
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 operationsid
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.)
5. Apply/Remove Labels on Messages
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 addaddLabelIds
: Array of label IDs to removeremoveLabelIds
: 15-16 char hex string for single operationsmessage_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 IDsmessage_id
6. Handle Drafts and Attachments
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 recipientrecipient_email
: Draft subject (omit for reply drafts to stay in thread)subject
: Draft contentbody
: Setis_html
for HTML contenttrue
: Object withattachment{s3key, mimetype, name}
: For reply drafts (leave subject empty to stay in thread)thread_id
Pitfalls:
- Response includes
(draft_id) ANDdata.id
; usedata.message.id
for 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
Common Patterns
ID Resolution
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 response
Thread ID from search:
1. Call GMAIL_FETCH_EMAILS or GMAIL_LIST_THREADS 2. Extract threadId (15-16 char hex string)
Pagination
- Set
up to 500 per pagemax_results - Check response for
nextPageToken - Pass token as
in next requestpage_token - Continue until
is absent or empty stringnextPageToken
is approximate, not exactresultSizeEstimate
Gmail Query Syntax
Operators:
- Emails from senderfrom:sender@example.com
- Emails to recipientto:recipient@example.com
- Subject contains exact phrasesubject:"exact phrase"
- Unread messagesis:unread
- Starred messagesis:starred
- Snoozed messagesis:snoozed
- Has attachmentshas:attachment
- After date (YYYY/MM/DD)after:2024/01/01
- Before datebefore:2024/12/31
- User-created label (use label ID)label:custom_label
- In sent folderin:sent
- Primary categorycategory:primary
Combinators:
- Both conditions (default)AND
- Either conditionOR
- Exclude conditionNOT
- Group conditions()
Examples:
- Unread emails from bossfrom:boss@company.com is:unread
- Invoices with attachments this yearsubject:invoice has:attachment after:2024/01/01
- Starred emails from Alice or 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
ordata_previewdata.messages - Parse defensively with fallbacks
- Timestamp
uses RFC3339 with 'Z' suffixmessageTimestamp - Normalize to '+00:00' for parsing if needed
Attachments:
- Attachment
from prior download may expires3key - Use promptly after retrieval
- Mimetype must include '/' separator
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) |
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
🏰 Rei Skills — Curated by Rootcastle Engineering & Innovation | Batuhan Ayrıbaş
Engineering Beyond Boundaries | admin@rootcastle.com