| name | gmail |
| version | 0.1.0 |
| author | devclaw |
| description | Gmail API — read, send, and manage emails via Gmail |
| category | communication |
| tags | ["gmail","email","google","mail","inbox"] |
| requires | {"bins":["curl","jq"],"env":["GMAIL_ACCESS_TOKEN"]} |
Gmail
Interact with Gmail using the Gmail API.
Setup
-
Check existing credentials:
vault_get gmail_access_token
-
If not configured:
The token is auto-injected as $GMAIL_ACCESS_TOKEN.
Note: Access tokens expire after ~1 hour; refresh and re-save when needed.
List Messages
curl -s "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=10" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" | jq '.messages'
curl -s "https://gmail.googleapis.com/gmail/v1/users/me/messages?q=is:unread+from:boss@company.com" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" | jq '.messages'
Read Message
curl -s "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID?format=full" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" | jq '{
id, snippet,
from: (.payload.headers[] | select(.name == "From") | .value),
subject: (.payload.headers[] | select(.name == "Subject") | .value),
date: (.payload.headers[] | select(.name == "Date") | .value)
}'
curl -s "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID?format=raw" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" | jq -r '.raw' | base64 -d
Send Email
RAW_EMAIL=$(cat <<EOF | base64 -w0
From: me@gmail.com
To: recipient@example.com
Subject: Test Email from DevClaw
This is the email body.
Can have multiple lines.
EOF
)
curl -s -X POST "https://gmail.googleapis.com/gmail/v1/users/me/messages/send" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"raw\": \"$RAW_EMAIL\"}"
Manage Labels
curl -s "https://gmail.googleapis.com/gmail/v1/users/me/labels" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" | jq '.labels[]'
curl -s -X POST "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID/modify" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"addLabelIds": ["Label_123"]}'
Mark as Read/Star
curl -s -X POST "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID/modify" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"removeLabelIds": ["UNREAD"]}'
curl -s -X POST "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID/modify" \
-H "Authorization: Bearer $GMAIL_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"addLabelIds": ["STARRED"]}'
Tips
- Access tokens expire after ~1 hour, refresh using refresh token
- Use
format=metadata for headers only (faster)
- Max results per request: 500
- Label IDs: INBOX, SENT, DRAFT, SPAM, TRASH, UNREAD, STARRED
Triggers
gmail, email, check email, send email, read gmail, inbox, gmail api