m26-resend-email

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

M26 Resend email automation

M26 Resend 邮件自动化

Assume the upstream layout
scripts/emails/
exists (or will be materialized). All procedures below use
cd
into
scripts/emails
, a venv, and
python <script>.py
unless the user is in a full monorepo from the repository root, where
python -m scripts.emails.<name>
is also valid.
假设上游目录结构中的
scripts/emails/
已存在(或即将生成)。以下所有操作都需要先
cd
进入
scripts/emails
目录
,使用 venv 虚拟环境,并运行
python <script>.py
命令,除非你处于代码仓库根目录的完整 monorepo 环境中,这种情况下也可以使用
python -m scripts.emails.<name>
命令。

First: materialize
scripts/emails

第一步:生成
scripts/emails
目录

If the folder is missing, obtain a sparse checkout of only that path (not the whole monorepo working tree). Full step-by-step commands, Windows junctions, and Linux symlinks live in
scripts/emails/MINIMAL_CLONE.md
in the upstream repo.
Minimum idea:
  1. Clone with
    --filter=blob:none --sparse
    , then
    git sparse-checkout init --no-cone
    and
    git sparse-checkout set --no-cone '/scripts/emails/'
    .
  2. cd scripts/emails
    , create
    .venv
    ,
    pip install -r requirements.txt
    , copy
    .env
    from
    .env.example
    (or from another machine — see below).
  3. Updates:
    git pull
    from the sparse clone root.
New machine / copied workspace: Copy
.env
and every file paths inside it (service account JSON, Gmail OAuth client JSON,
gmail_token.json
, etc.), then edit paths so they match the new filesystem. Copying
.env
alone often breaks because paths still point at the old PC. Agents should ask for missing keys or files before sending. Full checklist:
references/required-credentials.md
.
Do not run
python scripts/emails/foo.py
from the monorepo root
(path through
scripts/emails/
). Either
cd scripts/emails
and run
python foo.py
, or from full repo use
python -m scripts.emails.foo
.
Secrets stay in
.env
or the environment — never commit API keys, webhook secrets, or Gmail token files.
如果该文件夹不存在,请仅对该路径执行稀疏检出(sparse checkout)(不需要检出整个monorepo工作树)。完整的分步命令、Windows junction配置以及Linux符号链接说明都在上游仓库的
scripts/emails/MINIMAL_CLONE.md
文件中。
基础操作思路:
  1. 使用
    --filter=blob:none --sparse
    参数克隆仓库,然后执行
    git sparse-checkout init --no-cone
    git sparse-checkout set --no-cone '/scripts/emails/'
    命令。
  2. cd scripts/emails
    ,创建
    .venv
    虚拟环境,执行
    pip install -r requirements.txt
    ,从
    .env.example
    复制生成
    .env
    文件(也可以从其他机器复制,见下文说明)。
  3. 更新操作:在稀疏克隆的根目录执行
    git pull
新机器/复制的工作空间: 复制
.env
文件以及文件中引用的所有路径对应的文件(服务账号JSON、Gmail OAuth客户端JSON、
gmail_token.json
等),然后编辑路径使其匹配新的文件系统。仅复制
.env
文件通常会导致报错,因为路径仍然指向旧设备的地址。Agent在发送邮件前应该询问缺失的密钥或文件。完整检查清单见
references/required-credentials.md
不要在monorepo根目录运行
python scripts/emails/foo.py
命令(直接通过
scripts/emails/
路径调用)。要么
cd scripts/emails
后运行
python foo.py
,要么在完整仓库环境下使用
python -m scripts.emails.foo
命令。
密钥存储在
.env
文件或环境变量中——永远不要提交API密钥、webhook密钥或Gmail token文件到代码仓库。

Core scripts (from
scripts/emails
)

核心脚本(在
scripts/emails
目录下)

ScriptRole
send_campaign.py
Batch sends via Resend + Google Sheet rows
sync_replies_gmail.py
Pull inbox replies (Resend webhooks do not replace this)
webhook_server.py
Receives Resend events → Sheet columns (
opened_N
,
clicked_N
, …)
reply_followups.py
Threaded Gmail/Resend replies
build_utm_link.py
Build tracked links with consistent UTM params
Details, flags, and examples:
scripts/emails/README.md
. Operational guardrails:
scripts/emails/AGENTS.md
.
脚本作用
send_campaign.py
基于Resend + Google Sheet行数据批量发送邮件
sync_replies_gmail.py
拉取收件箱回复(Resend webhooks无法替代该功能)
webhook_server.py
接收Resend事件 → 写入Sheet列(
opened_N
clicked_N
等)
reply_followups.py
线程化Gmail/Resend回复
build_utm_link.py
生成带统一UTM参数的跟踪链接
详细说明、参数标识和示例见
scripts/emails/README.md
。操作规范见
scripts/emails/AGENTS.md

Resend behavior (short)

Resend行为说明(简版)

  • Opens/clicks: Emitted when domain-level open/click tracking is enabled in Resend; webhooks can fire
    email.opened
    / click events. Open rates are imperfect (clients blocking images, etc.).
  • Inbox replies: Not a substitute for
    sync_replies_gmail.py
    before follow-up sends.
  • 打开/点击统计: 当你在Resend中开启了域名级别的打开/点击跟踪时会生成对应数据;webhooks会触发
    email.opened
    / 点击事件。打开率统计存在误差(客户端拦截图片等原因)。
  • 收件箱回复: 发送跟进邮件前,不能用Resend的回复统计替代
    sync_replies_gmail.py
    的同步结果。

UTM and readable links

UTM和可读链接

Put long query strings in the HTML
href
(or Markdown
[visible text](url)
). Visible copy stays short; parameters stay on the URL. Parameter pattern and generators: see
references/utm-and-links.md
.
把长查询字符串放在 HTML
href
属性中(或者Markdown的
[可见文本](url)
格式中)。可见文案保持简洁,参数放在URL上。参数规范和生成器见
references/utm-and-links.md

Idempotency and safety

幂等性和安全说明

  • send_campaign
    :
    idempotency keys tie to campaign + chunk; reuse within 24h with a different body → 409. Use a test campaign id or
    --idempotency-suffix
    for experiments.
  • Before production sends:
    --dry-run
    ,
    --show-selected
    , validate templates.
  • send_campaign
    幂等性密钥与营销活动+分块绑定;24小时内使用相同密钥发送不同内容的邮件会返回 409 错误。进行测试时请使用测试营销活动ID或者添加
    --idempotency-suffix
    参数。
  • 正式发送前:使用
    --dry-run
    --show-selected
    参数验证模板。

When to load bundled references

何时需要查阅附带的参考文档

  • Clone/symlink mechanics, sparse-checkout pitfalls →
    references/clone-and-layout.md
  • .env
    , paths, copied key files, webhook vs send-only, PostHog
    references/required-credentials.md
  • UTM + link presentation →
    references/utm-and-links.md
  • Checklists (reply sync timing, batch columns, GIF env vars) →
    references/operational-rules.md
Upstream canonical copies evolve in
scripts/emails/MINIMAL_CLONE.md
and
scripts/emails/AGENTS.md
; refresh this skill when those change materially.
  • 克隆/符号链接机制、稀疏检出常见问题 →
    references/clone-and-layout.md
  • .env
    、路径、复制的密钥文件、webhook和仅发送模式、PostHog
    references/required-credentials.md
  • UTM + 链接展示规范 →
    references/utm-and-links.md
  • 检查清单(回复同步时间、批量列、GIF环境变量) →
    references/operational-rules.md
上游的标准版本会在
scripts/emails/MINIMAL_CLONE.md
scripts/emails/AGENTS.md
中更新;当这些文件发生重大变更时需要更新本技能。