gmail
Original:🇺🇸 English
Translated
1 scriptsChecked / no sensitive code detected
Manage Gmail messages, drafts, and labels. Send emails, search inbox, and organize email. Use when working with Gmail email management.
5installs
Sourceodyssey4me/agent-skills
Added on
NPX Install
npx skill4agent add odyssey4me/agent-skills gmailTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Gmail
Interact with Gmail for email management, search, and organization.
Installation
-
Install Python dependencies:bash
pip install --user google-auth google-auth-oauthlib google-api-python-client keyring pyyaml -
Download the skill from Releases or use directly from this repository.
Setup Verification
After installation, verify the skill is properly configured:
bash
python scripts/gmail.py checkThis will check:
- Python dependencies (google-auth, google-auth-oauthlib, google-api-python-client, keyring, pyyaml)
- Authentication configuration
- Connectivity to Gmail API
If anything is missing, the check command will provide setup instructions.
Authentication
Gmail uses OAuth 2.0 for authentication. For complete setup instructions, see:
- GCP Project Setup Guide - Create project, enable Gmail API
- Google OAuth Setup Guide - Configure credentials
Quick Start
-
Create:
~/.config/agent-skills/google.yamlyamloauth_client: client_id: your-client-id.apps.googleusercontent.com client_secret: your-client-secret -
Runto trigger OAuth flow and verify setup.
python scripts/gmail.py check
OAuth Scopes
The skill requests granular scopes for different operations:
| Scope | Permission | Used For |
|---|---|---|
| Read messages, labels, settings | Listing and reading messages |
| Send emails | Sending messages and drafts |
| Modify labels and metadata | Managing labels on messages |
| Manage labels | Creating and listing labels |
Scope Errors
If you encounter "insufficient scope" errors, revoke your token and re-authenticate:
- Revoke at https://myaccount.google.com/permissions
- Clear token:
keyring del agent-skills gmail-token-json - Re-run:
python scripts/gmail.py check
Commands
check
Verify configuration and connectivity.
bash
python scripts/gmail.py checkThis validates:
- Python dependencies are installed
- Authentication is configured
- Can connect to Gmail API
- Displays your email address and mailbox statistics
auth setup
Store OAuth 2.0 client credentials for custom OAuth flow.
bash
python scripts/gmail.py auth setup \
--client-id YOUR_CLIENT_ID \
--client-secret YOUR_CLIENT_SECRETCredentials are saved to .
~/.config/agent-skills/gmail.yamlmessages list
List messages matching a query.
bash
# List recent messages
python scripts/gmail.py messages list
# Search for unread messages
python scripts/gmail.py messages list --query "is:unread"
# Search with max results
python scripts/gmail.py messages list --query "from:user@example.com" --max-results 20
# Output as JSON
python scripts/gmail.py messages list --query "subject:meeting" --jsonArguments:
- : Gmail search query (optional)
--query - : Maximum number of results (default: 10)
--max-results - : Output as JSON
--json
Search Query Examples:
For complete Gmail search syntax, see gmail-queries.md.
Common queries:
- - Unread messages
is:unread - - Messages from sender
from:user@example.com - - Messages with subject keyword
subject:meeting - - Messages with attachments
has:attachment - - Messages after date
after:2024/01/01 - - Messages with label
label:important
messages get
Get a message by ID.
bash
# Get full message
python scripts/gmail.py messages get MESSAGE_ID
# Get minimal format
python scripts/gmail.py messages get MESSAGE_ID --format minimal
# Output as JSON
python scripts/gmail.py messages get MESSAGE_ID --jsonArguments:
- : The message ID (required)
message_id - : Message format (full, minimal, raw, metadata) - default: full
--format - : Output as JSON
--json
send
Send an email message.
bash
# Send simple email
python scripts/gmail.py send \
--to recipient@example.com \
--subject "Hello" \
--body "This is the message body"
# Send with CC and BCC
python scripts/gmail.py send \
--to recipient@example.com \
--subject "Team Update" \
--body "Here's the update..." \
--cc team@example.com \
--bcc boss@example.com
# Output as JSON
python scripts/gmail.py send \
--to user@example.com \
--subject "Test" \
--body "Test message" \
--jsonArguments:
- : Recipient email address (required)
--to - : Email subject (required)
--subject - : Email body text (required)
--body - : CC recipients (comma-separated)
--cc - : BCC recipients (comma-separated)
--bcc - : Output as JSON
--json
drafts list
List draft messages.
bash
# List drafts
python scripts/gmail.py drafts list
# List with custom max results
python scripts/gmail.py drafts list --max-results 20
# Output as JSON
python scripts/gmail.py drafts list --jsonArguments:
- : Maximum number of results (default: 10)
--max-results - : Output as JSON
--json
drafts create
Create a draft email.
bash
# Create draft
python scripts/gmail.py drafts create \
--to recipient@example.com \
--subject "Draft Subject" \
--body "This is a draft message"
# Create draft with CC
python scripts/gmail.py drafts create \
--to recipient@example.com \
--subject "Meeting Notes" \
--body "Notes from today's meeting..." \
--cc team@example.com
# Output as JSON
python scripts/gmail.py drafts create \
--to user@example.com \
--subject "Test Draft" \
--body "Draft body" \
--jsonArguments:
- : Recipient email address (required)
--to - : Email subject (required)
--subject - : Email body text (required)
--body - : CC recipients (comma-separated)
--cc - : BCC recipients (comma-separated)
--bcc - : Output as JSON
--json
drafts send
Send a draft message.
bash
# Send draft by ID
python scripts/gmail.py drafts send DRAFT_ID
# Output as JSON
python scripts/gmail.py drafts send DRAFT_ID --jsonArguments:
- : The draft ID to send (required)
draft_id - : Output as JSON
--json
labels list
List all Gmail labels.
bash
# List labels
python scripts/gmail.py labels list
# Output as JSON
python scripts/gmail.py labels list --jsonArguments:
- : Output as JSON
--json
labels create
Create a new label.
bash
# Create label
python scripts/gmail.py labels create "Project X"
# Output as JSON
python scripts/gmail.py labels create "Important" --jsonArguments:
- : Label name (required)
name - : Output as JSON
--json
Examples
Verify Setup
bash
python scripts/gmail.py checkFind unread emails
bash
python scripts/gmail.py messages list --query "is:unread"Search for emails from a sender
bash
python scripts/gmail.py messages list --query "from:boss@example.com" --max-results 5Send a quick email
bash
python scripts/gmail.py send \
--to colleague@example.com \
--subject "Quick Question" \
--body "Do you have time for a meeting tomorrow?"Create and send a draft
bash
# Create draft
python scripts/gmail.py drafts create \
--to team@example.com \
--subject "Weekly Update" \
--body "Here's this week's update..."
# List drafts to get the ID
python scripts/gmail.py drafts list
# Send the draft
python scripts/gmail.py drafts send DRAFT_IDOrganize with labels
bash
# Create a label
python scripts/gmail.py labels create "Project Alpha"
# List all labels
python scripts/gmail.py labels listAdvanced searches
bash
# Find emails with attachments from last week
python scripts/gmail.py messages list --query "has:attachment newer_than:7d"
# Find important emails from specific sender
python scripts/gmail.py messages list --query "from:ceo@example.com is:important"
# Find emails in a conversation
python scripts/gmail.py messages list --query "subject:project-alpha"Gmail Search Query Syntax
Common search operators:
| Operator | Description | Example |
|---|---|---|
| Sender email | |
| Recipient email | |
| Subject contains | |
| Has label | |
| Has attachment | |
| Unread messages | |
| Starred messages | |
| After date | |
| Before date | |
| Newer than period | |
| Older than period | |
Combine operators with spaces (implicit AND) or :
ORbash
# AND (implicit)
from:user@example.com subject:meeting
# OR
from:user@example.com OR from:other@example.com
# Grouping with parentheses
(from:user@example.com OR from:other@example.com) subject:meetingFor the complete reference, see gmail-queries.md.
Troubleshooting
Check command fails
Run to diagnose issues. It will provide specific error messages and setup instructions.
python scripts/gmail.py checkAuthentication failed
- Verify your OAuth client ID and client secret are correct in
~/.config/agent-skills/google.yaml - Token expired or corrupted - clear and re-authenticate:
bash
keyring del agent-skills gmail-token-json python scripts/gmail.py check
Permission denied
Your OAuth token may not have the necessary scopes. Revoke access at https://myaccount.google.com/permissions, clear your token, and re-authenticate.
Import errors
Ensure dependencies are installed:
bash
pip install --user google-auth google-auth-oauthlib google-api-python-client keyring pyyamlRate limiting
Gmail API has quota limits. If you hit rate limits, wait a few minutes before retrying. For high-volume usage, consider requesting quota increases in the Google Cloud Console.
API Scopes
This skill requests the following OAuth scopes:
- - Read email messages and settings
https://www.googleapis.com/auth/gmail.readonly - - Send email messages
https://www.googleapis.com/auth/gmail.send - - Modify labels and message metadata
https://www.googleapis.com/auth/gmail.modify - - Manage labels
https://www.googleapis.com/auth/gmail.labels
These scopes provide full email management capabilities while following the principle of least privilege.
Security Notes
- OAuth tokens are stored securely in your system keyring
- Client secrets are stored in with file permissions 600
~/.config/agent-skills/gmail.yaml - No passwords are stored - only OAuth tokens
- Tokens refresh automatically when using the skill
- Browser-based consent ensures you approve all requested permissions
Always review OAuth consent screens before granting access to your Gmail account.