gog
使用 gog 操作 Gmail、日曆、雲端硬碟、通訊錄、試算表和文件。需要設定 OAuth。
設定(一次性)
gog auth credentials /path/to/client_secret.jsongog auth add [email protected] --services gmail,calendar,drive,contacts,docs,sheetsgog auth list
常用指令
- Gmail 搜尋:
gog gmail search 'newer_than:7d' --max 10 - Gmail 郵件搜尋(依個別郵件,忽略對話串):
gog gmail messages search "in:inbox from:ryanair.com" --max 20 --account [email protected] - Gmail 傳送(純文字):
gog gmail send --to [email protected] --subject "Hi" --body "Hello" - Gmail 傳送(多行文字):
gog gmail send --to [email protected] --subject "Hi" --body-file ./message.txt - Gmail 傳送(標準輸入):
gog gmail send --to [email protected] --subject "Hi" --body-file - - Gmail 傳送(HTML):
gog gmail send --to [email protected] --subject "Hi" --body-html "<p>Hello</p>" - Gmail 草稿:
gog gmail drafts create --to [email protected] --subject "Hi" --body-file ./message.txt - Gmail 傳送草稿:
gog gmail drafts send <draftId> - Gmail 回覆:
gog gmail send --to [email protected] --subject "Re: Hi" --body "Reply" --reply-to-message-id <msgId> - 日曆列出事件:
gog calendar events <calendarId> --from <iso> --to <iso> - 日曆建立事件:
gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> - 日曆建立事件(含色彩):
gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> --event-color 7 - 日曆更新事件:
gog calendar update <calendarId> <eventId> --summary "New Title" --event-color 4 - 日曆顯示色彩:
gog calendar colors - 雲端硬碟搜尋:
gog drive search "query" --max 10 - 通訊錄:
gog contacts list --max 20 - 試算表讀取:
gog sheets get <sheetId> "Tab!A1:D10" --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 sheets metadata <sheetId> --json - 文件匯出:
gog docs export <docId> --format txt --out /tmp/doc.txt - 文件輸出內容:
gog docs cat <docId>
日曆色彩
- 使用
gog calendar colors查看所有可用的事件色彩(ID 1–11) - 使用
--event-color <id>旗標為事件加入色彩 - 事件色彩 ID(來自
gog calendar colors輸出):- 1: #a4bdfc
- 2: #7ae7bf
- 3: #dbadff
- 4: #ff887c
- 5: #fbd75b
- 6: #ffb878
- 7: #46d6db
- 8: #e1e1e1
- 9: #5484ed
- 10: #51b749
- 11: #dc2127
郵件格式
-
偏好純文字。對於多段落訊息,請使用
--body-file(或搭配標準輸入使用--body-file -)。 -
同一
--body-file模式也適用於草稿與回覆。 -
--body不會對\n進行跳脫處理。若需要內嵌換行,請使用 heredoc 或$'Line 1\n\nLine 2'。 -
僅在需要豐富格式時才使用
--body-html。 -
HTML 標籤:
<p>用於段落,<br>用於換行,<strong>用於粗體,<em>用於斜體,<a href="url">用於連結,<ul>/<li>用於列表。 -
範例(透過標準輸入的純文字):
gog gmail send --to [email protected] \ --subject "Meeting Follow-up" \ --body-file - <<'EOF' Hi Name, Thanks for meeting today. Next steps: - Item one - Item two Best regards, Your Name EOF -
範例(HTML 列表):
gog gmail send --to [email protected] \ --subject "Meeting Follow-up" \ --body-html "<p>Hi Name,</p><p>Thanks for meeting today. Here are the next steps:</p><ul><li>Item one</li><li>Item two</li></ul><p>Best regards,<br>Your Name</p>"
備註
- 設定
[email protected]可避免重複使用--account。 - 用於腳本時,建議使用
--json搭配--no-input。 - 試算表的值可以透過
--values-json(建議)或內嵌行傳入。 - 文件支援匯出/輸出內容/複製。原地編輯需要 Docs API 用戶端(不在 gog 中)。
- 傳送郵件或建立事件前會要求確認。
gog gmail search每個對話串回傳一行;若需要每個個別郵件分別回傳,請使用gog gmail messages search。