{"skill":{"slug":"gmail","displayName":"Gmail","summary":"Gmail API integration with managed OAuth. Read, send, and manage emails, threads, labels, and drafts. Use this skill when users want to interact with Gmail....","description":"---\nname: gmail\ndescription: |\n  Gmail API integration with managed OAuth. Read, send, and manage emails, threads, labels, and drafts. Use this skill when users want to interact with Gmail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).\ncompatibility: Requires network access and valid Maton API key\nmetadata:\n  author: maton\n  version: \"1.0\"\n  clawdbot:\n    emoji: 🧠\n    requires:\n      env:\n        - MATON_API_KEY\n---\n\n# Gmail\n\nAccess the Gmail API with managed OAuth authentication. Read, send, and manage emails, threads, labels, and drafts.\n\n## Quick Start\n\n**CLI:**\n\n```bash\nmaton google-mail message list -L 10\n```\n\n```bash\nmaton api '/google-mail/gmail/v1/users/me/messages?maxResults=10'\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/google-mail/gmail/v1/users/me/messages?maxResults=10')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n## Base URL\n\n```\nhttps://api.maton.ai/google-mail/{native-api-path}\n```\n\nMaton proxies requests to `gmail.googleapis.com` and automatically injects your OAuth token.\n\n## Installation\n\n**NPM:**\n```bash\nnpm install -g @maton-ai/cli\n```\n\n**Homebrew:**\n```bash\nbrew install maton-ai/cli/maton\n```\n\n## Authentication\n\n**CLI:**\n\n```bash\nmaton login                          # Opens browser for API key\nmaton login --interactive            # Skip browser, paste API key directly\nmaton whoami                         # Show current auth state\n```\n\n**Manual:**\n\n1. Sign in or create an account at [maton.ai](https://maton.ai)\n2. Go to [maton.ai/settings](https://maton.ai/settings)\n3. Copy your API key\n4. Set your API key as `MATON_API_KEY`:\n\n```bash\nexport MATON_API_KEY=\"YOUR_API_KEY\"\n```\n\n## Connection Management\n\nManage your Google OAuth connections at `https://api.maton.ai`.\n\n### List Connections\n\n**CLI:**\n\n```bash\nmaton connection list google-mail --status ACTIVE\n```\n\n```bash\nmaton api -X GET /connections -f app=google-mail -f status=ACTIVE\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/connections?app=google-mail&status=ACTIVE')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n### Create Connection\n\n**CLI:**\n\n```bash\nmaton connection create google-mail\n```\n\n```bash\nmaton api /connections -f app=google-mail\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\ndata = json.dumps({'app': 'google-mail'}).encode()\nreq = urllib.request.Request('https://api.maton.ai/connections', data=data, method='POST')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nreq.add_header('Content-Type', 'application/json')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n### Get Connection\n\n**CLI:**\n\n```bash\nmaton connection view {connection_id}\n```\n\n```bash\nmaton api /connections/{connection_id}\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/connections/{connection_id}')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n**Response:**\n```json\n{\n  \"connection\": {\n    \"connection_id\": \"{connection_id}\",\n    \"status\": \"ACTIVE\",\n    \"creation_time\": \"2025-12-08T07:20:53.488460Z\",\n    \"last_updated_time\": \"2026-01-31T20:03:32.593153Z\",\n    \"url\": \"https://connect.maton.ai/?session_token=...\",\n    \"app\": \"google-mail\",\n    \"metadata\": {}\n  }\n}\n```\n\nOpen the returned `url` in a browser to complete OAuth authorization.\n\n### Delete Connection\n\n**CLI:**\n\n```bash\nmaton connection delete {connection_id}\n```\n\n```bash\nmaton api -X DELETE /connections/{connection_id}\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/connections/{connection_id}', method='DELETE')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n### Specifying Connection\n\nIf you have multiple Gmail connections, specify which one to use:\n\n**CLI:**\n\n```bash\nmaton google-mail message list -L 10 --connection {connection_id}\n```\n\n```bash\nmaton api /google-mail/gmail/v1/users/me/messages --connection {connection_id}\n```\n\n**Python:**\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/google-mail/gmail/v1/users/me/messages')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nreq.add_header('Maton-Connection', '{connection_id}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\nIf you have multiple connections, always specify the connection to ensure requests go to the intended account.\n\n## Security & Permissions\n\n- Access is scoped to messages, threads, labels, drafts, and email sending within the connected Gmail account.\n- **All write operations require explicit user approval.** Before executing any create, update, or delete call, confirm the target resource and intended effect with the user.\n\n## API Reference\n\n### List Messages\n\n```bash\nGET /google-mail/gmail/v1/users/me/messages?maxResults=10\n```\n\nExample:\n\n```bash\nmaton google-mail message list -L 10\n```\n\nWith query filter:\n\n```bash\nGET /google-mail/gmail/v1/users/me/messages?q=is:unread&maxResults=10\n```\n\nExample:\n\n```bash\nmaton google-mail message list --query 'is:unread' -L 10\n```\n\n### Get Message\n\n```bash\nGET /google-mail/gmail/v1/users/me/messages/{messageId}\n```\n\nExample:\n\n```bash\nmaton google-mail message view {messageId} --headers\n```\n\nWith metadata only:\n\n```bash\nGET /google-mail/gmail/v1/users/me/messages/{messageId}?format=metadata&metadataHeaders=From&metadataHeaders=Subject&metadataHeaders=Date\n```\n\nExample:\n\n```bash\nmaton google-mail message view {messageId} --fetch-format metadata --metadata-header From,Subject,Date\n```\n\n### Send Message\n\n```bash\nPOST /google-mail/gmail/v1/users/me/messages/send\nContent-Type: application/json\n\n{\n  \"raw\": \"BASE64_ENCODED_EMAIL\"\n}\n```\n\nExample:\n\n```bash\nmaton google-mail message send --to alice@example.com --subject 'Hello' --body 'Hi there!'\n```\n\n### Reply to Message\n\n```bash\nmaton google-mail message reply {messageId} --body 'Thanks!'\n```\n\n### Forward Message\n\n```bash\nmaton google-mail message forward {messageId} --to dave@example.com --body 'FYI'\n```\n\n### List Labels\n\n```bash\nGET /google-mail/gmail/v1/users/me/labels\n```\n\nExample:\n\n```bash\nmaton google-mail label list\n```\n\n### List Threads\n\n```bash\nGET /google-mail/gmail/v1/users/me/threads?maxResults=10\n```\n\nExample:\n\n```bash\nmaton google-mail thread list -L 10\n```\n\n### Get Thread\n\n```bash\nGET /google-mail/gmail/v1/users/me/threads/{threadId}\n```\n\nExample:\n\n```bash\nmaton google-mail thread view {threadId}\n```\n\n### Modify Message Labels\n\n```bash\nPOST /google-mail/gmail/v1/users/me/messages/{messageId}/modify\nContent-Type: application/json\n\n{\n  \"addLabelIds\": [\"STARRED\"],\n  \"removeLabelIds\": [\"UNREAD\"]\n}\n```\n\nExample:\n\n```bash\nmaton google-mail message modify {messageId} --add-label STARRED --remove-label UNREAD\n```\n\n### Trash Message\n\n```bash\nPOST /google-mail/gmail/v1/users/me/messages/{messageId}/trash\n```\n\nExample:\n\n```bash\nmaton google-mail message trash {messageId}\n```\n\n### Create Draft\n\n```bash\nPOST /google-mail/gmail/v1/users/me/drafts\nContent-Type: application/json\n\n{\n  \"message\": {\n    \"raw\": \"BASE64URL_ENCODED_EMAIL\"\n  }\n}\n```\n\nExample:\n\n```bash\nmaton google-mail draft create --to alice@example.com --subject 'Hello' --body 'Draft content here'\n```\n\n### Send Draft\n\n```bash\nPOST /google-mail/gmail/v1/users/me/drafts/send\nContent-Type: application/json\n\n{\n  \"id\": \"{draftId}\"\n}\n```\n\nExample:\n\n```bash\nmaton google-mail draft send {draftId}\n```\n\n### Get Profile\n\n```bash\nGET /google-mail/gmail/v1/users/me/profile\n```\n\n## Query Operators\n\nUse in the `q` parameter:\n- `is:unread` - Unread messages\n- `is:starred` - Starred messages\n- `from:email@example.com` - From specific sender\n- `to:email@example.com` - To specific recipient\n- `subject:keyword` - Subject contains keyword\n- `after:2024/01/01` - After date\n- `before:2024/12/31` - Before date\n- `has:attachment` - Has attachments\n\n## Code Examples\n\n### CLI\n\n```bash\n# List unread messages with headers\nmaton google-mail message list --hydrate\n\n# Filter with jq — e.g., only messages from a specific sender\nmaton google-mail message list -L 20 --query 'from:boss@example.com' --json --jq '.messages[].id'\n\n# List all threads with pagination\nmaton google-mail thread list --paginate --query 'newer_than:7d'\n```\n\n### JavaScript\n\n```javascript\nconst response = await fetch(\n  'https://api.maton.ai/google-mail/gmail/v1/users/me/messages?maxResults=10',\n  {\n    headers: {\n      'Authorization': `Bearer ${process.env.MATON_API_KEY}`\n    }\n  }\n);\n```\n\n### Python\n\n```python\nimport os\nimport requests\n\nresponse = requests.get(\n    'https://api.maton.ai/google-mail/gmail/v1/users/me/messages',\n    headers={'Authorization': f'Bearer {os.environ[\"MATON_API_KEY\"]}'},\n    params={'maxResults': 10, 'q': 'is:unread'}\n)\n```\n\n## Notes\n\n- Use `me` as userId for the authenticated user\n- Message body is base64url encoded in the `raw` field\n- Common labels: `INBOX`, `SENT`, `DRAFT`, `STARRED`, `UNREAD`, `TRASH`\n- IMPORTANT: When using curl commands, use `curl -g` when URLs contain brackets (`fields[]`, `sort[]`, `records[]`) to disable glob parsing\n- IMPORTANT: When piping curl output to `jq` or other commands, environment variables like `$MATON_API_KEY` may not expand correctly in some shell environments. You may get \"Invalid API key\" errors when piping.\n\n## Error Handling\n\n| Status | Meaning |\n|--------|---------|\n| 400 | Missing Gmail connection |\n| 401 | Invalid or missing Maton API key |\n| 429 | Rate limited (10 req/sec per account) |\n| 4xx/5xx | Passthrough error from Gmail API |\n\n### Troubleshooting: API Key Issues\n\n**CLI:**\n\n1. Check your auth state:\n\n```bash\nmaton whoami\n```\n\n2. Verify the API key is valid by listing connections:\n\n```bash\nmaton connection list\n```\n\n**Manual:**\n\n1. Check that the `MATON_API_KEY` environment variable is set:\n\n```bash\necho $MATON_API_KEY\n```\n\n2. Verify the API key is valid by listing connections:\n\n```bash\npython <<'EOF'\nimport urllib.request, os, json\nreq = urllib.request.Request('https://api.maton.ai/connections')\nreq.add_header('Authorization', f'Bearer {os.environ[\"MATON_API_KEY\"]}')\nprint(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))\nEOF\n```\n\n### Troubleshooting: Invalid App Name\n\n1. Ensure your URL path starts with `google-mail`. For example:\n\n- Correct: `https://api.maton.ai/google-mail/gmail/v1/users/me/messages`\n- Incorrect: `https://api.maton.ai/gmail/v1/users/me/messages`\n\n## Resources\n\n- [Gmail API Overview](https://developers.google.com/gmail/api/reference/rest)\n- [List Messages](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list)\n- [Get Message](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get)\n- [Send Message](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send)\n- [List Threads](https://developers.google.com/gmail/api/reference/rest/v1/users.threads/list)\n- [List Labels](https://developers.google.com/gmail/api/reference/rest/v1/users.labels/list)\n- [Create Draft](https://developers.google.com/gmail/api/reference/rest/v1/users.drafts/create)\n- [Maton CLI Manual](https://cli.maton.ai/manual)\n- [Maton Community](https://discord.com/invite/dBfFAcefs2)\n- [Maton Support](mailto:support@maton.ai)\n","tags":{"latest":"1.0.8"},"stats":{"comments":3,"downloads":37582,"installsAllTime":330,"installsCurrent":326,"stars":72,"versions":9},"createdAt":1770021074275,"updatedAt":1781739760978},"latestVersion":{"version":"1.0.8","createdAt":1778148211420,"changelog":"- Added CLI usage examples throughout documentation for common Gmail operations.\n- Included installation instructions for Maton CLI via NPM and Homebrew.\n- Expanded Quick Start and Connection Management sections to cover both CLI and Python methods.\n- Added specific CLI commands for sending, replying, and forwarding messages, as well as label and thread management.\n- Improved organization and clarity for multi-connection scenarios and authentication steps.","license":"MIT-0"},"metadata":{"setup":[{"key":"MATON_API_KEY","required":true}],"os":null,"systems":null},"owner":{"handle":"byungkyu","userId":"s174c3s2kc1ehqj1ytzntezj2983e2aj","displayName":"byungkyu","image":"https://avatars.githubusercontent.com/u/16563684?v=4"},"moderation":null}