AgentSkillsCN

gmail

Gmail管理技能。OAuth 2.0认证、收发邮件、标签管理。当请求中包含“gmail”、“邮件确认”、“发邮件”时使用。

SKILL.md
--- frontmatter
name: gmail
description: >
  Gmail management skill. OAuth 2.0 authentication, read/send mail, label management.
  Use when requests include "gmail", "메일 확인", "이메일 보내줘".
version: 1.0.0
triggers:
  keywords:
    - "gmail"
    - "지메일"
    - "email"
    - "이메일"
    - "메일"
    - "mail"
    - "inbox"
    - "받은편지함"
    - "unread"
    - "안읽은 메일"
    - "메일 확인"
    - "메일 보내"
    - "이메일 전송"
  patterns:
    - "gmail (login|inbox|unread|send|read|search|labels)"
    - "(메일|이메일).*(확인|읽|보내|전송|검색)"
    - "(unread|inbox|sent) (mail|email)"
  file_patterns:
    - "**/gmail*.py"
    - "**/gmail_*.json"
  context:
    - "Gmail integration"
    - "Email automation"
    - "Mail management"
capabilities:
  - gmail_oauth
  - send_email
  - read_inbox
  - search_emails
  - manage_labels
model_preference: sonnet
auto_trigger: true

Gmail Skill

Gmail API integration skill. Provides OAuth 2.0 authentication, read/send email, and label management.

Prerequisites

1. Google Cloud Console Setup

  1. Open https://console.cloud.google.com/
  2. Select or create a project
  3. Go to APIs & Services > Library
  4. Search for Gmail API and click Enable

2. Create OAuth Credentials

  1. Go to APIs & Services > Credentials
  2. Create Credentials > OAuth client ID
  3. Application type: Desktop app
  4. Name: Gmail CLI (or any name)
  5. Click Create

3. Download Credentials

  1. On the created OAuth client, click Download JSON
  2. Save the file to C:\claude\json\desktop_credentials.json

File structure example:

json
{
  "installed": {
    "client_id": "xxx.apps.googleusercontent.com",
    "client_secret": "xxx",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "redirect_uris": ["http://localhost"]
  }
}

4. OAuth Consent Screen

  1. APIs & Services > OAuth consent screen
  2. User Type: External (or Internal if Google Workspace)
  3. Fill in App name, User support email, Developer contact
  4. Scopes: add gmail.readonly, gmail.send, gmail.modify
  5. Test users: add your own email (if in test mode)

5. Run Authentication

powershell
cd C:\claude && python -m lib.gmail login
  • A browser opens showing the Google account selector
  • After consent, the token is saved automatically
  • Token location: C:\claude\json\token_gmail.json

Commands

CommandDescription
python -m lib.gmail loginOAuth login (first-time only)
python -m lib.gmail statusCheck auth status
python -m lib.gmail inboxView inbox
python -m lib.gmail unreadView unread mail
python -m lib.gmail read <email_id>Read email details
python -m lib.gmail send <to> <subject> <body>Send email
python -m lib.gmail search <query>Search emails
python -m lib.gmail labelsList labels
python -m lib.gmail mark-read <email_id>Mark as read
python -m lib.gmail archive <email_id>Archive
python -m lib.gmail trash <email_id>Move to trash

Usage Examples

Inbox

powershell
# 10 most recent
python -m lib.gmail inbox

# 20 most recent (JSON output)
python -m lib.gmail inbox --limit 20 --json

Unread

powershell
# List unread
python -m lib.gmail unread

# JSON output
python -m lib.gmail unread --json

Search

powershell
# From a specific sender
python -m lib.gmail search "from:boss@company.com"

# Subject contains keyword
python -m lib.gmail search "subject:meeting"

# With attachments
python -m lib.gmail search "has:attachment"

# Date range
python -m lib.gmail search "after:2024/01/01 before:2024/12/31"

# Combined search
python -m lib.gmail search "from:client@example.com subject:invoice has:attachment"

Send

powershell
# Plain text
python -m lib.gmail send "recipient@example.com" "Meeting agenda" "Please attend tomorrow at 3pm."

# With CC
python -m lib.gmail send "recipient@example.com" "Weekly report" "See attached" --cc "manager@example.com"

# HTML mail
python -m lib.gmail send "recipient@example.com" "Notice" "<h1>Notice</h1><p>Details...</p>" --html

Read Details

powershell
# By email ID
python -m lib.gmail read "18d5f7c8e9a0b123"

# Mark as read as well
python -m lib.gmail read "18d5f7c8e9a0b123" --mark-read

Python API

python
from lib.gmail import GmailClient, login, get_token

# Auth (first time)
login()

# Create client
client = GmailClient()

# Inbox
emails = client.list_emails(query="in:inbox", max_results=10)
for email in emails:
    print(f"{email.sender}: {email.subject}")

# Unread
unread = client.list_emails(query="is:unread", max_results=5)

# Search
results = client.list_emails(query="from:boss@company.com", max_results=20)

# Send
result = client.send(
    to="recipient@example.com",
    subject="Hello",
    body="Email body."
)
print(f"Sent: {result.permalink}")

# Reply
client.reply(email_id="...", body="Reply content")

# Labels
labels = client.list_labels()
client.modify_labels(email_id, add_labels=["STARRED"])

# Read/unread
client.mark_as_read(email_id)
client.mark_as_unread(email_id)

# Archive/trash
client.archive(email_id)
client.trash(email_id)

Claude Mandatory Execution Rules (MANDATORY)

When Gmail keywords are detected, Claude MUST do the following automatically.

Step 1: Check auth status (always first)

powershell
cd C:\claude && python -m lib.gmail status --json

Result interpretation:

  • "authenticated": true, "valid": true -> proceed to Step 2
  • "authenticated": false -> instruct the user to log in:
    code
    Gmail authentication required. Run:
    python -m lib.gmail login
    

Step 2: Run command for the request

User RequestCommand to Run
"메일 확인해줘"python -m lib.gmail inbox --json
"안읽은 메일"python -m lib.gmail unread --json
"메일 보내줘"python -m lib.gmail send "addr" "subject" "body"
"메일 검색"python -m lib.gmail search "query" --json
"라벨 목록"python -m lib.gmail labels --json
"이 메일 읽어줘"python -m lib.gmail read "ID" --json

Step 3: Parse JSON result and respond

Parse the --json flag output and present to the user in a readable form.

Example — unread mail:

json
{"count": 3, "emails": [{"id": "...", "subject": "Meeting agenda", "from": "boss@example.com", ...}]}

-> "You have 3 unread messages:\n1. boss@example.com - Meeting agenda\n2. ..."

Required (MUST)

RuleDescription
cd C:\claude && prefixRun modules from project root
Use --json flagEasier result parsing
Use Bash tool directlyExecute lib/gmail CLI
Detailed guidance on errorsAuth steps, OAuth setup, etc.

Prohibited (NEVER)

ProhibitedReason
Read gmail_token.json directlySecurity risk
Call Gmail API via WebFetchOAuth token required
Respond "no infrastructure"CLI is directly runnable via Bash
Ask user to run manuallyClaude should execute directly

Gmail Search Query Syntax

FilterQuery Example
Senderfrom:example@gmail.com
Recipientto:me@gmail.com
Subjectsubject:meeting
Attachmenthas:attachment
Unreadis:unread
Readis:read
Starredis:starred
Importantis:important
After dateafter:2024/01/01
Before datebefore:2024/12/31
Labellabel:work
Inboxin:inbox
Sentin:sent
Spamin:spam
Trashin:trash

Error Handling

ErrorSolution
GmailCredentialsNotFoundErrorCreate desktop_credentials.json
GmailAuthErrorRe-run python -m lib.gmail login
GmailRateLimitErrorRetry after a moment
403 Permission DeniedCheck scopes on the OAuth Consent Screen

File Locations

FilePurpose
C:\claude\json\desktop_credentials.jsonOAuth client (user-created)
C:\claude\json\token_gmail.jsonAccess token (auto-generated)
C:\claude\lib\gmail\Library source code

Rate Limits

Respects Gmail API 2026 rate limits:

  • Reads: 250 requests/sec
  • Sends: 100/min (standard account)
  • Bulk sends: Google Workspace account required

/auto Option Integration

The /auto --gmail option can inject Gmail context into a task.

code
/auto --gmail "Analyze recent client mail and draft replies"
-> Step 1: Check Gmail auth
-> Step 2: Search/fetch mail
-> Step 3: Use analysis as context
-> Step 4: Run main workflow

Security Notes

  • OAuth tokens are stored locally only
  • Auto-refresh via refresh_token
  • Re-authentication required upon expiry
  • credentials.json is never committed (.gitignore)