Files
atlas/blogwatcher-daily/references/agentmail-sending.md

75 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AgentMail 发送邮件工作流(配合 blogwatcher-daily 等导出技能)
> 从 blogwatcher-daily 的 SKILL.md 中拆出,因为「AgentMail 发信」是独立于「RSS 抓取导出」的能力。任何需要先导出再发邮件的场景都可复用。
## 前置条件
- `agentmail` CLI 已安装(`/opt/homebrew/bin/agentmail`)
- API key 在 `~/.zshrc` 的 `AGENTMAIL_API_KEY` 里(当前 Hermes shell 不会自动加载 .zshrc,需手动 source 或提取)
- **出站网络需要走代理**:`ALL_PROXY=socks5://127.0.0.1:10808`(否则 agentmail API 返回 403 被 CloudFront 拦截)
## 标准发送流程
```bash
# 1) 提取 API key + 设置代理(每次新 shell 都要做)
export AGENTMAIL_API_KEY=$(grep '^export AGENTMAIL_API_KEY=' ~/.zshrc | sed 's/.*="\(.*\)"/\1/')
export ALL_PROXY=socks5://127.0.0.1:10808
export HTTP_PROXY=http://127.0.0.1:10808
export HTTPS_PROXY=http://127.0.0.1:10808
# 2) 列出 inbox 拿 inbox_id(首次;一般是 star-agent@agentmail.to)
agentmail inboxes list
# 3) 发送(--html 直接读 HTML 内容字符串)
agentmail inboxes messages send \
--inbox-id "star-agent@agentmail.to" \
--to "billyshen@163.com" \
--subject "主题" \
--html "$(cat /tmp/file.html)"
```
返回 JSON:
```json
{
"message_id": "<...>@email.amazonses.com",
"thread_id": "..."
}
```
## 常见陷阱
### 1. 403 "Request blocked"
- 没走代理。CloudFront 拦了直连 IP。
- 修复:export 上面 3 个 PROXY 环境变量后重试。
### 2. 401 "credentials are missing"
- 当前 shell 没加载 .zshrc,`AGENTMAIL_API_KEY` 不在环境里。
- 修复:用上面的 `export $(grep ...)` 提取。
### 3. HTML 太长
- `--html "$(cat file)"` 把整个文件塞进命令行参数。对很大的 HTML(>500KB)可能撞到 ARG_MAX。
- 应对:先压缩 HTML(去掉 base64 图片、压缩 CSS),或者改用 `--json @payload.json` 走 stdin。
## 与 blogwatcher-daily 配合的固定模式
```bash
# 导出 → 发邮件
python3 ~/.hermes/skills/custom/blogwatcher-daily/scripts/blogwatcher-daily.py \
--export html --date 2026-08-30 > /tmp/digest.html
agentmail inboxes messages send \
--inbox-id "star-agent@agentmail.to" \
--to "billyshen@163.com" \
--subject "Blogwatcher Daily Digest $(date +%Y-%m-%d)" \
--html "$(cat /tmp/digest.html)"
```
## 当前用户的 inbox
- `star-agent@agentmail.to`(默认发件箱)
## 已发送示例
- Blogwatcher 每日摘要 → billyshen@163.com
- 单订阅文章打包(异次元软件世界、惫懒の欧阳川)→ billyshen@163.com