gog-extended
Complete reference for the gog CLI with focus on advanced Gmail operations (full email bodies, attachments, complex searches).
Setup (one-time)
CODEBLOCK0
Gmail Operations
Search & Browse
- - Search threads (one row per thread):
CODEBLOCK1
- - Search individual messages (ignores threading, returns all matches):
CODEBLOCK2
Read Full Email Content (Critical for Automation)
This is the key difference from basic search — retrieve the complete email body, headers, and content:
CODEBLOCK3
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):
CODEBLOCK4
The HTML format makes it easier to identify structure (tables, divs, links) and extract data without dealing with raw MIME encoding.
Download Attachments
CODEBLOCK5
Get attachment IDs from gog gmail get <messageId> --format=full output.
Send Emails
CODEBLOCK6
CODEBLOCK7
- - Multi-line (via stdin):
CODEBLOCK8
CODEBLOCK9
Drafts
CODEBLOCK10
Reply to Messages
CODEBLOCK11
Gmail History (Last Changes)
CODEBLOCK12
Gmail URL Links
CODEBLOCK13
Prints direct Gmail web URLs.
Calendar Operations
List Events
CODEBLOCK14
Create Event
CODEBLOCK15
With color (IDs 1–11):
CODEBLOCK16
Update Event
CODEBLOCK17
View Color Palette
CODEBLOCK18
Color IDs:
- - 1: #a4bdfc (blue)
- 2: #7ae7bf (teal)
- 3: #dbadff (purple)
- 4: #ff887c (red)
- 5: #fbd75b (yellow)
- 6: #ffb878 (orange)
- 7: #46d6db (cyan)
- 8: #e1e1e1 (gray)
- 9: #5484ed (dark blue)
- 10: #51b749 (green)
- 11: #dc2127 (dark red)
Drive Operations
CODEBLOCK19
Contacts
CODEBLOCK20
Sheets
Read Data
CODEBLOCK21
Update Data
CODEBLOCK22
Append Data
CODEBLOCK23
Clear Data
CODEBLOCK24
Docs
Export
CODEBLOCK25
Read (cat)
CODEBLOCK26
Advanced Flags
Common Flags
- -
--account you@gmail.com — Target specific account (required when multiple accounts configured) - INLINECODE4 — Output JSON (best for scripting)
- INLINECODE5 — Stable TSV format (no colors)
- INLINECODE6 — Preview changes without executing
- INLINECODE7 — Skip confirmations
- INLINECODE8 — Never prompt (useful for CI/automation)
- INLINECODE9 — Enable verbose logging
Environment Variable
Avoid repeating --account by setting:
CODEBLOCK27
Then:
CODEBLOCK28
Gmail Query Syntax
Powerful search operators for gog gmail search and gog gmail messages search:
- -
newer_than:7d — Last 7 days - INLINECODE14 — Before date
- INLINECODE15 — After date
- INLINECODE16 — From specific sender
- INLINECODE17 — To specific recipient
- INLINECODE18 — Subject contains
- INLINECODE19 — In inbox (also:
sent, draft, starred, important) - INLINECODE24 — Unread messages
- INLINECODE25 — Has attachment
- INLINECODE26 — Attachment name
- INLINECODE27 — Custom labels
Complex queries:
CODEBLOCK29
Notes
- - Search vs Messages:
gog gmail search returns one row per thread; use gog gmail messages search when you need every individual email. - Multi-account: When multiple accounts are configured, always specify
--account email@domain.com. - Token efficiency: For scripting, use
--json output and parse programmatically. - Email body extraction: Use
gog gmail get <messageId> --format=full to retrieve complete email content (critical for automation like order tracking, invoice extraction, etc.). - Docs are read-only in gog: In-place edits require a separate Docs API client; gog supports export and read-only operations.
gog-extended
gog CLI的完整参考,专注于高级Gmail操作(完整邮件正文、附件、复杂搜索)。
设置(一次性)
bash
gog auth credentials /path/to/client_secret.json
gog auth add you@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
gog auth list
Gmail操作
搜索与浏览
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
读取完整邮件内容(自动化关键)
这是与基本搜索的关键区别——检索完整的邮件正文、头部和内容:
bash
带HTML正文的完整邮件(推荐用于解析和自动化)
gog gmail get
--format=full --account you@example.com
仅元数据(更快,无正文)
gog gmail get --format=metadata --account you@example.com
原始RFC 2822格式(MIME编码)
gog gmail get --format=raw --account you@example.com
建议: 使用--format=full(默认),返回HTML格式的邮件正文。HTML比原始RFC 2822更好地保留结构、链接和格式,便于程序化解析和提取数据。
示例工作流程(从邮件中提取订单详情):
bash
1. 查找邮件
gog gmail messages search from:order@example.com subject:confirmation --max 1 --account you@example.com
2. 从结果中提取邮件ID
3. 读取完整内容(返回HTML正文,便于解析)
gog gmail get --format=full --account you@example.com
4. 解析HTML获取数据(grep、sed或HTML解析器)
gog gmail get --format=full --account you@example.com | grep -i order\|price\|quantity
HTML格式使识别结构(表格、div、链接)和提取数据更容易,无需处理原始MIME编码。
下载附件
bash
gog gmail attachment
从gog gmail get --format=full输出中获取附件ID。
发送邮件
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 - <This is a test.
Cheers
EOF
bash
gog gmail send --to a@b.com --subject Hi --body-html Hello
草稿
bash
gog gmail drafts create --to a@b.com --subject Hi --body-file ./message.txt
gog gmail drafts send
回复邮件
bash
gog gmail send --to a@b.com --subject Re: Hi --body Reply --reply-to-message-id
Gmail历史记录(最近更改)
bash
gog gmail history --max 100
Gmail URL链接
bash
gog gmail url ...
打印直接的Gmail网页URL。
日历操作
列出事件
bash
gog calendar events --from 2026-01-01T00:00:00Z --to 2026-12-31T23:59:59Z
创建事件
bash
gog calendar create --summary Meeting --from 2026-03-30T10:00:00Z --to 2026-03-30T11:00:00Z
带颜色(ID 1–11):
bash
gog calendar create --summary Important --from 2026-03-30T10:00:00Z --to 2026-03-30T11:00:00Z --event-color 4
更新事件
bash
gog calendar update --summary New Title --event-color 7
查看调色板
bash
gog calendar colors
颜色ID:
- - 1: #a4bdfc(蓝色)
- 2: #7ae7bf(青色)
- 3: #dbadff(紫色)
- 4: #ff887c(红色)
- 5: #fbd75b(黄色)
- 6: #ffb878(橙色)
- 7: #46d6db(青色)
- 8: #e1e1e1(灰色)
- 9: #5484ed(深蓝色)
- 10: #51b749(绿色)
- 11: #dc2127(深红色)
云端硬盘操作
bash
gog drive search filename:report.pdf --max 10
gog drive search in:starred --max 20
联系人
bash
gog contacts list --max 20
gog contacts list --max 50 --json
表格
读取数据
bash
gog sheets get Tab!A1:D10 --json
gog sheets metadata --json
更新数据
bash
gog sheets update Tab!A1:B2 --values-json [[A,B],[1,2]] --input USER_ENTERED
追加数据
bash
gog sheets append Tab!A:C --values-json [[x,y,z]] --insert INSERT_ROWS
清除数据
bash
gog sheets clear Tab!A2:Z
文档
导出
bash
gog docs export --format txt --out /tmp/doc.txt
gog docs export --format pdf --out /tmp/doc.pdf
读取(cat)
bash
gog docs cat
高级标志
常用标志
- - --account you@gmail.com — 指定目标账户(配置多个账户时必需)
- --json — 输出JSON(最适合脚本编写)
- --plain — 稳定的TSV格式(无颜色)
- --dry-run — 预览更改而不执行
- --force — 跳过确认
- --no-input — 从不提示(适用于CI/自动化)
- --verbose — 启用详细日志记录
环境变量
通过设置以下内容避免重复使用--account:
bash
export GOG_ACCOUNT=you@gmail.com
然后:
bash
gog gmail search newerthan:7d # 自动使用GOGACCOUNT
Gmail查询语法
用于gog gmail search和gog gmail messages search的强大搜索运算符:
- - newerthan:7d — 最近7天
- before:2026-03-30 — 在日期之前
- after:2026-03-20 — 在日期之后
- from:sender@example.com — 来自特定发件人
- to:recipient@example.com — 发送给特定收件人
- subject:keywords — 主题包含
- in:inbox — 在收件箱中(还有:sent、draft、starred、important)
- is:unread — 未读邮件
- has:attachment — 有附件
- filename:document.pdf — 附件名称
- label:customlabel — 自定义标签
复杂查询:
bash
gog gmail search from:billing@example.com subject:invoice after:2026-03-01
gog gmail search in:inbox is