Email

邮件模板

Nebutra 邮件目录项、公开发送函数和预览产物。

邮件模板的所有权集中在 packages/integrations/email/src/index.tsEMAIL_TEMPLATE_CATALOG 定义每个模板的 catalog ID、公开发送函数和预览文件名。

模板参考

Catalog ID函数必填参数重点
welcomesendWelcomeEmailto, firstName, orgName
order-confirmationsendOrderConfirmationEmailto, orderId, totalAmount, items
api-key-createdsendApiKeyCreatedEmailto, firstName, keyPrefix, keyName, plaintextKey
quota-warningsendQuotaWarningEmailto, orgName, metric, used, limit, percentUsed
team-invitationsendInviteEmailto, inviterName, orgName, role, inviteUrl
magic-linksendMagicLinkEmailto, magicLinkUrl
contact-form-receivedsendContactFormReceivedEmailto, name, subject
checkout-completedsendCheckoutCompletedEmailto, firstName, orgName, planName
trial-endingsendTrialEndingEmailto, firstName, orgName, trialEndDate
invoice-paidsendInvoicePaidEmailto, orgName, invoiceId, amountPaid
payment-failedsendPaymentFailedEmailto, orgName, attemptCount
subscription-canceledsendSubscriptionCanceledEmailto, firstName, orgName
upcoming-invoicesendUpcomingInvoiceEmailto, orgName, amountDue
plan-changedsendPlanChangedEmailto, firstName, orgName, newPlan
license-createdsendLicenseCreatedEmailto, firstName, licenseKey, tier

示例

import { sendInvoicePaidEmail } from "@nebutra/email";

await sendInvoicePaidEmail({
  to: "[email protected]",
  orgName: "Acme Corp",
  invoiceId: "in_123",
  amountPaid: 9900,
  currency: "USD",
  invoiceUrl: "https://billing.stripe.com/invoice/in_123",
});

新增或修改模板

  1. packages/integrations/email/src/index.ts 新增或更新公开发送函数。
  2. 新增或更新匹配的 EMAIL_TEMPLATE_CATALOG 项。
  3. 重新生成或校验 apps/mail-preview/dist 里的预览产物。
  4. 公开接口变化时更新 packages/integrations/email/src/__tests__/email-contract.test.ts
  5. 运行验证:
pnpm --filter @nebutra/email test
pnpm --filter @nebutra/email typecheck
pnpm mail:check

不要把生成的预览 HTML 当成源头手工编辑。先改包里的目录和发送函数。

How is this guide?

目录