Complete reference for the gog CLI with focus on advanced Gmail operations (full email bodies, attachments, complex searches).
gog auth credentials /path/to/client_secret.json
gog auth add you@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
gog auth list
```bash
gog gmail search 'newer_than:7d' --max 10
gog gmail search 'from:sender@example.com' --max 20
```
```bash
gog gmail messages search "in:inbox from:ryanair.com" --max 20 --account you@example.com
gog gmail messages search 'subject:invoice' --max 50
```
This is the key difference from basic search — retrieve the complete email body, headers, and content:
# Full email with HTML body (recommended for parsing and automation)
gog gmail get <messageId> --format=full --account you@example.com
# Metadata only (faster, no body)
gog gmail get <messageId> --format=metadata --account you@example.com
# Raw RFC 2822 format (MIME encoded)
gog gmail get <messageId> --format=raw --account you@example.com
Recommendation: Use --format=full (default) which returns HTML-formatted email bodies. HTML preserves structure, links, and formatting better than raw RFC 2822, making it easier to parse and extract data programmatically.
Example workflow (extracting order details from email):
# 1. Find the message
gog gmail messages search 'from:order@example.com subject:confirmation' --max 1 --account you@example.com
# 2. Extract the message ID from results
# 3. Read full content (returns HTML body for easy parsing)
gog gmail get <messageId> --format=full --account you@example.com
# 4. Parse HTML for data (grep, sed, or HTML parser)
gog gmail get <messageId> --format=full --account you@example.com | grep -i "order\|price\|quantity"
The HTML format makes it easier to identify structure (tables, divs, links) and extract data without dealing with raw MIME encoding.
gog gmail attachment <messageId> <attachmentId>
Get attachment IDs from gog gmail get output.
```bash
gog gmail send --to a@b.com --subject "Hi" --body "Hello"
```
```bash
gog gmail send --to a@b.com --subject "Hi" --body-file ./message.txt
```
```bash
gog gmail send --to a@b.com --subject "Hi" --body-file - <<'EOF'
Hi there,
This is a test.
Cheers
EOF
```
```bash
gog gmail send --to a@b.com --subject "Hi" --body-html "
Hello
"```
gog gmail drafts create --to a@b.com --subject "Hi" --body-file ./message.txt
gog gmail drafts send <draftId>
gog gmail send --to a@b.com --subject "Re: Hi" --body "Reply" --reply-to-message-id <msgId>
gog gmail history --max 100
gog gmail url <threadId> ...
Prints direct Gmail web URLs.
gog calendar events <calendarId> --from 2026-01-01T00:00:00Z --to 2026-12-31T23:59:59Z
gog calendar create <calendarId> --summary "Meeting" --from 2026-03-30T10:00:00Z --to 2026-03-30T11:00:00Z
With color (IDs 1–11):
gog calendar create <calendarId> --summary "Important" --from 2026-03-30T10:00:00Z --to 2026-03-30T11:00:00Z --event-color 4
gog calendar update <calendarId> <eventId> --summary "New Title" --event-color 7
gog calendar colors
Color IDs:
gog drive search "filename:report.pdf" --max 10
gog drive search "in:starred" --max 20
gog contacts list --max 20
gog contacts list --max 50 --json
gog sheets get <sheetId> "Tab!A1:D10" --json
gog sheets metadata <sheetId> --json
gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]' --input USER_ENTERED
gog sheets append <sheetId> "Tab!A:C" --values-json '[["x","y","z"]]' --insert INSERT_ROWS
gog sheets clear <sheetId> "Tab!A2:Z"
gog docs export <docId> --format txt --out /tmp/doc.txt
gog docs export <docId> --format pdf --out /tmp/doc.pdf
gog docs cat <docId>
--account you@gmail.com — Target specific account (required when multiple accounts configured)--json — Output JSON (best for scripting)--plain — Stable TSV format (no colors)--dry-run — Preview changes without executing--force — Skip confirmations--no-input — Never prompt (useful for CI/automation)--verbose — Enable verbose loggingAvoid repeating --account by setting:
export GOG_ACCOUNT=you@gmail.com
Then:
gog gmail search 'newer_than:7d' # Uses GOG_ACCOUNT automatically
Powerful search operators for gog gmail search and gog gmail messages search:
newer_than:7d — Last 7 daysbefore:2026-03-30 — Before dateafter:2026-03-20 — After datefrom:sender@example.com — From specific senderto:recipient@example.com — To specific recipientsubject:keywords — Subject containsin:inbox — In inbox (also: sent, draft, starred, important)is:unread — Unread messageshas:attachment — Has attachmentfilename:document.pdf — Attachment namelabel:custom_label — Custom labelsComplex queries:
gog gmail search 'from:billing@example.com subject:invoice after:2026-03-01'
gog gmail search 'in:inbox is:unread has:attachment'
gog gmail search returns one row per thread; use gog gmail messages search when you need every individual email.--account email@domain.com.--json output and parse programmatically.gog gmail get --format=full to retrieve complete email content (critical for automation like order tracking, invoice extraction, etc.).共 1 个版本