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 |
服务器错误或网络错误 |










