EngageLab Email CLI
EngageLab Email CLI 協助 Agent 和開發者透過命令列處理入站與出站郵件。
可用於:
- 列出可用的信箱
- 列出與檢視郵件對話
- 讀取入站郵件
- 輪詢新的入站郵件
- 回覆入站郵件
- 傳送新郵件
安裝
npm install -g @engagelabemail/cli
檢視已安裝的版本:
engagelab-email-cli -V
當你執行連線到 EngageLab Email 的指令時,CLI 會檢查是否有更新的 CLI 版本。如果需要更新,它會停止並顯示更新指令:
npm install -g @engagelabemail/cli@latest
設定
管理已儲存的設定
使用 config 指令群組來儲存、檢視或清除本機認證。
在本機儲存服務位址與金鑰:
engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx
檢視已儲存的設定:
engagelab-email-cli config list
清除已儲存的設定:
engagelab-email-cli config clear
config list 會對金鑰進行遮罩處理。
在任何業務指令中使用全域認證
你不必先儲存認證。可以直接在任何業務指令(如 threads ... 或 emails ...)之前傳遞 --base-url 和 --secret-key。這些命令列認證僅適用於目前指令,不會覆寫已儲存的設定。
範例:
engagelab-email-cli --base-url http://localhost:8087 --secret-key sk_xxx threads get thread-1
快速開始
列出最近的入站郵件:
engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20
讀取一封入站郵件:
engagelab-email-cli emails receiving get <message-uid>
檢視某封郵件的完整對話:
engagelab-email-cli threads messages <thread-id> --include-content --limit 10
回覆入站郵件:
engagelab-email-cli emails receiving reply <message-uid> --subject "Re: Hello" --text "Thanks, we received your message."
傳送新郵件:
engagelab-email-cli emails send \
--mailbox-id 1001 \
--to alice@example.com \
--subject "Hello" \
--text "Hello from EngageLab Email CLI."
對於指令碼或 Agent,加入 --json 以取得機器可讀的輸出:
engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20 --json
指令
config set
儲存本機設定。
| 選項 | 說明 |
|---|---|
--base-url <url> |
服務位址。如果設定了環境變數,預設為 ENGAGELAB_EMAIL_BASE_URL。 |
--secret-key <key> |
金鑰。如果設定了環境變數,預設為 ENGAGELAB_EMAIL_SECRET_KEY。 |
範例:
engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx
config list
顯示已儲存的設定。
範例:
engagelab-email-cli config list
config clear
清除已儲存的本機設定,包含 baseUrl 和 secretKey。
範例:
engagelab-email-cli config clear
mailbox list
列出可用的信箱。
| 選項 | 說明 |
|---|---|
--mailbox <address> |
依信箱位址過濾。 |
--page-no <number> |
頁碼。 |
--page-size <number> |
每頁數量。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli mailbox list --page-size 20
threads list
列出郵件對話。
| 選項 | 說明 |
|---|---|
--mailbox-id <id> |
依信箱 ID 過濾。 |
--subject <text> |
依正規化後的主旨搜尋。 |
--participant <email> |
依參與者搜尋。 |
--start-time <timestamp> |
最新郵件的開始時間戳(毫秒)。 |
--end-time <timestamp> |
最新郵件的結束時間戳(毫秒)。 |
--page-no <number> |
頁碼。 |
--page-size <number> |
每頁數量。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli threads list --subject refund --page-no 1 --page-size 20
threads get <thread-id>
顯示單一對話。
| 參數/選項 | 說明 |
|---|---|
<thread-id> |
對話 ID。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli threads get b0d9d6a1-1d17-4df8-8245-c807d7e8cb50
threads messages <thread-id>
列出對話中的郵件。
| 參數/選項 | 說明 |
|---|---|
<thread-id> |
對話 ID。 |
--limit <number> |
郵件數量限制。 |
--include-content |
包含文字/HTML/標頭/附件。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli threads messages b0d9d6a1-1d17-4df8-8245-c807d7e8cb50 --include-content --json
emails receiving list
列出入站郵件。
| 選項 | 說明 |
|---|---|
--mailbox-id <id> |
依信箱 ID 過濾。 |
--keyword <text> |
搜尋關鍵字。 |
--page-no <number> |
頁碼。 |
--page-size <number> |
每頁數量。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli emails receiving list --keyword refund --page-size 20
emails receiving get <message-uid>
顯示單封入站郵件。
| 參數/選項 | 說明 |
|---|---|
<message-uid> |
郵件 UID。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli emails receiving get 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 --json
emails receiving listen
輪詢新的入站郵件。此指令會持續執行,直到用 Ctrl+C 停止。
| 選項 | 說明 |
|---|---|
--after <id> |
上一次結果的游標 ID。 |
--limit <number> |
郵件數量限制。 |
--interval <seconds> |
輪詢間隔(秒),最小 2 秒。 |
--json |
每列輸出一個 JSON 郵件。 |
範例:
engagelab-email-cli emails receiving listen --limit 10 --interval 5 --json
從已知游標繼續:
engagelab-email-cli emails receiving listen --after 1500 --limit 10 --interval 5 --json
emails receiving reply <message-uid>
回覆入站郵件。
| 參數/選項 | 說明 |
|---|---|
<message-uid> |
要回覆的郵件 UID。 |
--subject <text> |
回覆主旨。 |
--text <text> |
純文字內文。 |
--html <html> |
HTML 內文。 |
--text-file <path> |
從檔案讀取純文字內文。 |
--html-file <path> |
從檔案讀取 HTML 內文。 |
--cc <email> |
副本位址。可重複使用。 |
--bcc <email> |
密件副本位址。可重複使用。 |
--reply-to <email> |
回覆位址。可重複使用。 |
--preview-text <text> |
郵件預覽文字。 |
--attachment <path> |
附加本機檔案。可重複使用。必須配合 --disposition 使用。最多 10 個檔案,base64 編碼後總計不超過 10MB(約 7.5MB 原始檔案)。 |
--disposition <value> |
附件類型:attachment 或 inline。使用 --attachment 時必須指定。可重複使用或為所有附件一次性指定。 |
--content-id <id> |
內嵌圖片附件的 Content-ID。當圖片附件使用 --disposition inline 時必須指定。 |
--sandbox |
沙箱模式傳送。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli emails receiving reply 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 \
--subject "Re: Refund update" \
--text "Thanks, we received your message." \
--attachment ./receipt.pdf \
--disposition attachment
emails send
傳送新郵件。
| 選項 | 說明 |
|---|---|
--mailbox-id <id> |
信箱 ID。 |
--from <email> |
寄件者郵件位址。 |
--to <email> |
收件者郵件位址。可重複使用。 |
--subject <text> |
郵件主旨。 |
--text <text> |
純文字內文。 |
--html <html> |
HTML 內文。 |
--text-file <path> |
從檔案讀取純文字內文。 |
--html-file <path> |
從檔案讀取 HTML 內文。 |
--cc <email> |
副本位址。可重複使用。 |
--bcc <email> |
密件副本位址。可重複使用。 |
--reply-to <email> |
回覆位址。可重複使用。 |
--preview-text <text> |
郵件預覽文字。 |
--attachment <path> |
附加本機檔案。可重複使用。必須配合 --disposition 使用。最多 10 個檔案,base64 編碼後總計不超過 10MB(約 7.5MB 原始檔案)。 |
--disposition <value> |
附件類型:attachment 或 inline。使用 --attachment 時必須指定。可重複使用或為所有附件一次性指定。 |
--content-id <id> |
內嵌圖片附件的 Content-ID。當圖片附件使用 --disposition inline 時必須指定。 |
--sandbox |
沙箱模式傳送。 |
--json |
輸出原始 JSON。 |
範例:
engagelab-email-cli emails send \
--mailbox-id 1001 \
--to alice@example.com \
--to bob@example.com \
--subject "Refund update" \
--text "Your refund has been processed." \
--attachment ./receipt.pdf \
--disposition attachment
傳送帶有內嵌圖片附件的 HTML:
engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000
附件中繼資料可以透過兩種相容的方式傳遞。推薦的方式將中繼資料繫結到每個檔案路徑,這樣可以避免多個附件時的歧義:
engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Mixed attachments" --html "<p>Logo <img src=cid:image_1000></p>" --attachment "./receipt.pdf;disposition=attachment" --attachment "./logo.png;disposition=inline;content_id=image_1000"
為了相容性,也支援傳統的分離選項形式:
engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000
請勿在同一指令中混合使用內嵌附件中繼資料形式(path;disposition=...)與 --disposition 或 --content-id。
從檔案傳送 HTML 內容:
engagelab-email-cli emails send \
--mailbox-id 1001 \
--to alice@example.com \
--subject "Monthly report" \
--html-file ./report.html
輸出
預設情況下,CLI 列印可讀的表格或摘要,並在請求執行時顯示簡短的載入訊息。
當其他工具或指令碼需要解析結果時,使用 --json。
engagelab-email-cli emails receiving get <message-uid> --json
emails receiving listen --json 每列輸出一個郵件 JSON 物件。
錯誤
當 API 傳回業務錯誤碼時,人類可讀的錯誤會包含該錯誤碼,例如 [100101] unauthorized。
--json 錯誤使用以下格式:
{
"error": {
"code": "auth_error",
"errorCode": 100101,
"message": "unauthorized"
}
}
結束碼:
| 結束碼 | 意義 |
|---|---|
1 |
參數錯誤或設定遺失 |
2 |
認證失敗 |
3 |
找不到資源 |
4 |
衝突或進行中狀態 |
5 |
伺服器錯誤或網路錯誤 |










