微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📧

零配置 OAuth,安全操控 Gmail

Gmail · v1.0.7
专业技能 安全 S+ 级 榜单 #47 作者 byungkyu 公开目录收录
32.4k 下载 66 安装 90k 收藏 86 浏览

简介

通过 Maton 托管 OAuth 安全访问 Gmail API,实现邮件收发、标签管理与草稿操作,需显式确认写操作。

原始描述

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....

通过你的 Agent 添加

安装目录:gmail/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/gmail/
Codex CLI~/.codex/skills/gmail/
DeepSeek Harness~/.agents/skills/gmail/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Gmail Skill 提供对 Gmail API 的完整代理访问,通过 Maton 平台托管 OAuth 认证,用户无需自行处理 Google OAuth 流程。支持读取邮件、发送邮件、管理标签与草稿、操作会话线程等核心功能。

认证流程:设置 MATON_API_KEY 环境变量 → 创建 Google OAuth 连接 → 浏览器完成授权 → 通过 Authorization: Bearer 头调用 API。多账户场景下可使用 Maton-Connection 头指定目标账户。

基础端点模式:https://api.maton.ai/google-mail/{native-gmail-api-path},原生 Gmail API 路径直接透传。

显著优点

  1. 零配置 OAuth:Maton 托管完整的 OAuth 生命周期,免除开发者注册 Google Cloud 项目、配置同意屏幕、管理刷新令牌等繁琐工作
  2. 标准 API 语义:完全兼容 Gmail REST API 规范,可直接参照 Google 官方文档开发
  3. 多账户支持:通过 Connection 头轻松切换多个 Gmail 账户
  4. 丰富查询能力:支持完整的 Gmail 搜索运算符(is:unread, from:, after:等)

潜在缺点与局限性

  • 速率限制:单账户 10 req/s,高并发场景需自行限流
  • 代理依赖:服务可用性绑定 Maton 平台,非直连 Google
  • Base64 编码负担:发送邮件需自行处理 RFC 2822 消息的 Base64URL 编码
  • 功能白名单:仅支持文档列出的端点,非完整 Gmail API 覆盖

适合人群

  • 快速原型开发:需立即集成邮件功能,不愿投入 OAuth 工程成本
  • 多账户管理工具:需要统一接口操作多个 Gmail 账户
  • 自动化工作流:结合查询运算符构建邮件筛选、归档、通知流水线

常规风险

  • 写操作确认:文档明确要求所有创建/更新/删除操作前需用户显式确认,防止误删或误发
  • API Key 泄露:MATON_API_KEY 泄露将导致账户级别的未授权访问
  • OAuth 范围:实际权限取决于用户授权时同意的 Google 权限范围
  • 数据隐私:邮件内容流经 Maton 代理服务器,需评估第三方数据驻留合规性

技能正文


name: gmail description: | 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). compatibility: Requires network access and valid Maton API key metadata: author: maton version: "1.0" clawdbot: emoji: 🧠 requires: env: - MATON_API_KEY

Gmail

Access the Gmail API with managed OAuth authentication. Read, send, and manage emails, threads, labels, and drafts.

Quick Start

# List messages
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-mail/gmail/v1/users/me/messages?maxResults=10')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Base URL

https://gateway.maton.ai/google-mail/{native-api-path}

Replace {native-api-path} with the actual Gmail API endpoint path. The gateway proxies requests to gmail.googleapis.com and automatically injects your OAuth token.

Authentication

All requests require the Maton API key in the Authorization header:

Authorization: Bearer $MATON_API_KEY

Environment Variable: Set your API key as MATON_API_KEY:

export MATON_API_KEY="YOUR_API_KEY"

Getting Your API Key

  1. Sign in or create an account at maton.ai
  2. Go to maton.ai/settings
  3. Copy your API key

Connection Management

Manage your Google OAuth connections at https://ctrl.maton.ai.

List Connections

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=google-mail&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Create Connection

python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'google-mail'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Get Connection

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Response:

{
  "connection": {
    "connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
    "status": "ACTIVE",
    "creation_time": "2025-12-08T07:20:53.488460Z",
    "last_updated_time": "2026-01-31T20:03:32.593153Z",
    "url": "https://connect.maton.ai/?session_token=...",
    "app": "google-mail",
    "metadata": {}
  }
}

Open the returned url in a browser to complete OAuth authorization.

Delete Connection

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Specifying Connection

If you have multiple Gmail connections, specify which one to use with the Maton-Connection header:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-mail/gmail/v1/users/me/messages')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

If omitted, the gateway uses the default (oldest) active connection.

API Reference

List Messages

GET /google-mail/gmail/v1/users/me/messages?maxResults=10

With query filter:

GET /google-mail/gmail/v1/users/me/messages?q=is:unread&maxResults=10

Get Message

GET /google-mail/gmail/v1/users/me/messages/{messageId}

With metadata only:

GET /google-mail/gmail/v1/users/me/messages/{messageId}?format=metadata&metadataHeaders=From&metadataHeaders=Subject&metadataHeaders=Date

Send Message

POST /google-mail/gmail/v1/users/me/messages/send
Content-Type: application/json

{
  "raw": "BASE64_ENCODED_EMAIL"
}

List Labels

GET /google-mail/gmail/v1/users/me/labels

List Threads

GET /google-mail/gmail/v1/users/me/threads?maxResults=10

Get Thread

GET /google-mail/gmail/v1/users/me/threads/{threadId}

Modify Message Labels

POST /google-mail/gmail/v1/users/me/messages/{messageId}/modify
Content-Type: application/json

{
  "addLabelIds": ["STARRED"],
  "removeLabelIds": ["UNREAD"]
}

Trash Message

POST /google-mail/gmail/v1/users/me/messages/{messageId}/trash

Create Draft

POST /google-mail/gmail/v1/users/me/drafts
Content-Type: application/json

{
  "message": {
    "raw": "BASE64URL_ENCODED_EMAIL"
  }
}

Send Draft

POST /google-mail/gmail/v1/users/me/drafts/send
Content-Type: application/json

{
  "id": "{draftId}"
}

Get Profile

GET /google-mail/gmail/v1/users/me/profile

Query Operators

Use in the q parameter:

  • is:unread - Unread messages
  • is:starred - Starred messages
  • from:email@example.com - From specific sender
  • to:email@example.com - To specific recipient
  • subject:keyword - Subject contains keyword
  • after:2024/01/01 - After date
  • before:2024/12/31 - Before date
  • has:attachment - Has attachments

Code Examples

JavaScript

const response = await fetch(
  'https://gateway.maton.ai/google-mail/gmail/v1/users/me/messages?maxResults=10',
  {
    headers: {
      'Authorization': `Bearer ${process.env.MATON_API_KEY}`
    }
  }
);

Python

import os
import requests

response = requests.get(
    "https://gateway.maton.ai/google-mail/gmail/v1/users/me/messages",
    headers={"Authorization": f"Bearer {os.environ['MATON_API_KEY']}"},
    params={"maxResults": 10, "q": "is:unread"},
)

Notes

  • Use me as userId for the authenticated user
  • Message body is base64url encoded in the raw field
  • Common labels: INBOX, SENT, DRAFT, STARRED, UNREAD, TRASH
  • IMPORTANT: When using curl commands, use curl -g when URLs contain brackets (fields[], sort[], records[]) to disable glob parsing
  • 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.

Error Handling

Status Meaning
400 Missing Gmail connection
401 Invalid or missing Maton API key
429 Rate limited (10 req/sec per account)
4xx/5xx Passthrough error from Gmail API

Troubleshooting: API Key Issues

  1. Check that the MATON_API_KEY environment variable is set:
echo $MATON_API_KEY
  1. Verify the API key is valid by listing connections:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Troubleshooting: Invalid App Name

  1. Ensure your URL path starts with google-mail. For example:
  • Correct: https://gateway.maton.ai/google-mail/gmail/v1/users/me/messages
  • Incorrect: https://gateway.maton.ai/gmail/v1/users/me/messages

Resources

正文来自原始仓库, 版权归作者所有,许可:MIT。 权利人认为有不妥,可申请下架。

原始仓库

作者的项目地址:https://github.com/CraftOS-dev/CraftBot

标签

emailgmailoauthgoogle-apimessagingautomationproductivity

同类 Skill