Operate Gmail with the gog CLI.
Execution path: gog
Authenticated account: (account authenticated with gog)
Execution Notes
execWhen running with the tool,timeout: 60specify- For large searches,
--maxlimit
Email search
Basic search
gog gmail search "<query>"
gog gmail search "is:unread" --max 10
gog gmail search "from:someone@example.com"
Search query list
| Query | Description |
|---|---|
is:unread |
Unread |
is:starred |
Starred |
is:important |
Important |
from:xxx |
Sender |
to:xxx |
Recipient |
cc:xxx |
CC |
subject:xxx |
Contains in subject |
"キーワード" |
Exact match search |
has:attachment |
Has attachment |
filename:pdf |
PDF file attached |
larger:5M |
5MB or larger |
smaller:1M |
1MB or smaller |
after:YYYY/MM/DD |
On or after specified date |
before:YYYY/MM/DD |
On or before specified date |
older_than:7d |
Older than 7 days |
newer_than:3d |
Within 3 days |
label:xxx |
Specific label |
in:inbox |
Inbox |
in:sent |
Sent |
in:trash |
Trash |
in:anywhere |
All (including trash) |
Compound search examples
# 田中さんから今週届いた未読メール
gog gmail search "from:tanaka is:unread newer_than:7d"
# 請求書関連の添付ファイル付きメール
gog gmail search "subject:請求書 has:attachment"
# 2026年1月以降のPDF添付メール
gog gmail search "filename:pdf after:2026/01/01"
Email retrieval
Thread/message retrieval
# メッセージ詳細(本文込み)
gog gmail get <messageId>
# メタデータのみ
gog gmail messages get <messageId> --format metadata
Attachment download
gog gmail attachment <messageId> <attachmentId>
gog gmail attachment <messageId> <attachmentId> --output "./download.pdf"
Email sending
Basic send
gog gmail send \
--to "recipient@example.com" \
--subject "件名" \
--body "本文テキスト"
With CC/BCC
gog gmail send \
--to "main@example.com" \
--cc "copy1@example.com,copy2@example.com" \
--bcc "hidden@example.com" \
--subject "件名" \
--body "本文"
With attachment
gog gmail send \
--to "recipient@example.com" \
--subject "資料送付" \
--body "添付ファイルをご確認ください。" \
--attach "./report.pdf" \
--attach "./data.xlsx"
HTML body
gog gmail send \
--to "recipient@example.com" \
--subject "HTMLメール" \
--body-html "<h1>見出し</h1><p>本文です。</p>"
Read body from file
gog gmail send \
--to "recipient@example.com" \
--subject "長文メール" \
--body-file "./email_body.txt"
Reply
Reply to thread
gog gmail send \
--thread-id "<threadId>" \
--to "original-sender@example.com" \
--subject "Re: 元の件名" \
--body "返信本文"
Reply directly to message
gog gmail send \
--reply-to-message-id "<messageId>" \
--to "original-sender@example.com" \
--subject "Re: 元の件名" \
--body "返信本文"
Reply all
gog gmail send \
--reply-to-message-id "<messageId>" \
--reply-all \
--subject "Re: 元の件名" \
--body "全員への返信"
Label operations
Label list
gog gmail labels list
Add/remove label
# ラベル追加
gog gmail thread modify <threadId> --add-labels "重要"
# ラベル削除
gog gmail thread modify <threadId> --remove-labels "UNREAD"
# 既読にする
gog gmail thread modify <threadId> --remove-labels "UNREAD"
# アーカイブ
gog gmail thread modify <threadId> --remove-labels "INBOX"
Send option list
| Options | Description |
|---|---|
--to |
Recipient (required, multiple allowed separated by commas) |
--cc |
CC (comma-separated) |
--bcc |
BCC (comma-separated) |
--subject |
Subject (required) |
--body |
Body (plain text) |
--body-html |
HTML body |
--body-file |
Body file (- でstdin) |
--attach |
Attachment (multiple allowed) |
--thread-id |
Reply destination thread ID |
--reply-to-message-id |
Reply destination message ID |
--reply-all |
Reply all |
--from |
Source address (send alias) |
--reply-to |
Reply-To header |
Output options
| Options | Description |
|---|---|
--json |
JSON output |
--plain |
TSV output |
--max N |
Max N items |
--all |
Retrieve all pages |
Typical workflows
Check unread emails → reply
# 1. 未読検索
gog gmail search "is:unread" --max 5 --json
# 2. 詳細確認
gog gmail get <messageId>
# 3. 返信
gog gmail send \
--reply-to-message-id "<messageId>" \
--to "sender@example.com" \
--subject "Re: 件名" \
--body "ご連絡ありがとうございます。..."
Search attachments → download
# 1. 検索
gog gmail search "from:client has:attachment" --json
# 2. メッセージ取得(添付ID確認)
gog gmail get <messageId> --json
# 3. ダウンロード
gog gmail attachment <messageId> <attachmentId> --output "./downloaded.pdf"
Message list
gog gmail messages # 受信メッセージ一覧
gog gmail messages --max 20 --json
Thread operations
# スレッド取得(スレッド内の全メッセージ)
gog gmail thread <threadId>
gog gmail thread <threadId> --json
# スレッドのラベル変更
gog gmail thread modify <threadId> --add-labels "重要"
gog gmail thread modify <threadId> --remove-labels "UNREAD"
Draft operations
# 下書き一覧
gog gmail drafts list
gog gmail drafts list --json
# 下書き作成
gog gmail drafts create \
--to "recipient@example.com" \
--subject "件名" \
--body "本文"
# 下書き送信
gog gmail drafts send <draftId>
# 下書き削除
gog gmail drafts delete <draftId>
Top-level send command
gog send is a shortcut for sending email:
gog send --to "recipient@example.com" --subject "件名" --body "本文"
gog gmail send Equivalent to.
Notes
- Long body:
--body-fileuse - Special characters: Beware of shell escaping
- Mass sending: Beware of rate limits
- When replying: Add "Re: " to the subject