@beignet/provider-mail-resend

中文文档
0.0.65发布于 2026/11/08MITTypeScriptES Module近 30 天下载 1897

Resend mail provider for Beignet - adds mailer port using Resend

原始使用文档
文档目录10 节
  1. Install
  2. Setup
  3. Use in application code
  4. Attachments and inline images
  5. Escape hatch
  6. Devtools
  7. Failure and retry semantics
  8. Local and tests
  9. Deployment notes
  10. License

@beignet/provider-mail-resend

Runtime: Beignet requires Node.js 22.12 or newer. Bun is optional.

[!CAUTION] Beignet is experimental alpha software. The 0.0.x package line is for early evaluation, and APIs may change between releases while the framework settles.

Resend-backed mail provider for Beignet.

The provider installs the app-facing ctx.ports.mailer port and exposes ctx.ports.resend.client only as an escape hatch for Resend-specific features.

createResendMailProvider(...) returns the stable ResendMailProvider type. ResendMailConfig describes its validated config; the Zod schema remains internal.

Install

bun add @beignet/provider-mail-resend @beignet/core resend

The provider requires resend ^6.14.0 for attachment metadata support. Upgrade older SDK installations with bun add resend@^6.14.0. Beignet's Node.js 22.12-or-newer runtime baseline also satisfies Resend v6's requirement.

Setup

import { createResendMailProvider } from "@beignet/provider-mail-resend";
import { createServer } from "@beignet/core/server";

const server = await createServer({
  ports: basePorts,
  providers: [createResendMailProvider()],
  context: ({ ports }) => ({ ports }),
  routes,
});

Required environment variables:

VariableDescription
RESEND_API_KEYResend API key
RESEND_FROMDefault sender, e.g. My App <[email protected]>

beignet doctor --strict checks that installed Resend mail providers are registered in server/providers.ts and that both required env vars are present in app env examples or config.

Use createResendMailProvider(...) when you want to pass config directly instead of reading RESEND_* env vars. Options override env-derived values:

import { createResendMailProvider } from "@beignet/provider-mail-resend";

export const providers = [
  createResendMailProvider({
    apiKey: secrets.resendApiKey,
    from: "My App <[email protected]>",
  }),
];

Calling createResendMailProvider() with no options uses the env-backed configuration.

Use in application code

await ctx.ports.mailer.send({
  to: "[email protected]",
  subject: "Welcome",
  html: "<h1>Hello</h1>",
});

The same MailerPort works with SMTP, memory fakes, and other adapters:

await ctx.ports.mailer.send({
  from: { email: "[email protected]", name: "Support" },
  to: ["[email protected]", "[email protected]"],
  replyTo: "[email protected]",
  subject: "Account updated",
  text: "Your account was updated.",
  html: "<p>Your account was updated.</p>",
});

Attachments and inline images

Send files through the standard mailer:

await ctx.ports.mailer.send({
  to: "[email protected]",
  subject: "Workspace summary",
  text: "Your summary is attached.",
  attachments: [
    {
      filename: "summary.json",
      content: new TextEncoder().encode(JSON.stringify({ completed: 12 })),
      contentType: "application/json",
    },
  ],
});

Each MailAttachment requires a nonblank filename without control characters and content: Uint8Array; Node.js Buffers also work. Optional contentType specifies a MIME type without parameters; the provider infers it from the filename when omitted. Set contentId: "logo" on an image attachment and reference it with <img src="cid:logo"> in the HTML body to embed the image. IDs must be unique per message: 1–127 letters, digits, dots, underscores, @, +, or -, beginning with a letter or digit. Omit the cid: prefix from the attachment's ID.

The shared mailer copies metadata and bytes before delivery, permits empty files, and rejects invalid attachment fields with MailDeliveryError before calling the vendor. It accepts bytes rather than paths, URLs, streams, or base64 strings. Provider size and file-type limits apply. Attachment names, bytes, and content IDs are excluded from mail instrumentation.

Use createMemoryMailer() from @beignet/core/mail to assert mailer.deliveries[0].message.attachments in tests. Queued jobs and notifications should carry storage keys or JSON-safe source data; construct attachment bytes in the handler or channel renderer.

Escape hatch

Use the Resend client only when you need a Resend-specific feature not covered by MailerPort:

await ctx.ports.resend.client.emails.send({
  from: "[email protected]",
  to: "[email protected]",
  subject: "Invoice",
  html: "<p>Your invoice is ready.</p>",
  tags: [{ name: "category", value: "invoice" }],
});

The provider contributes:

  • ctx.ports.mailer, the standard Beignet MailerPort
  • ctx.ports.resend, an escape hatch with the Resend client

Devtools

When ctx.ports.devtools is installed, this provider records mail.send, mail.sent, and mail.failed events under the mail watcher. Completed and failed events include durationMs in their details. Events retain the provider, recipient count, delivery ID when available, and duration, but never include addresses, subjects, message bodies, or raw Resend errors.

Failure and retry semantics

The provider fails fast and does not retry. Each send(...) call makes one Resend SDK call, even for transient network errors or provider-side failures. Mail delivery is not idempotent: a timed-out send may still have been delivered, so a blind provider retry risks duplicate emails.

Delivery failures throw MailDeliveryError from @beignet/core/mail with the provider name, the recipient count, and the original Resend error preserved as cause for app-owned handling. The error is not copied into provider instrumentation. Redact or restrict access when an application logs the cause. Startup configuration problems throw during provider setup.

When mail needs retries, dispatch it from a job or an outbox-backed listener and own idempotency there. The job or outbox row should choose attempts and delay, and the application should record one delivery per business event before sending.

Local and tests

Use a memory or fake MailerPort in use-case tests. Keep Resend sandbox or test-mode credentials in environment-specific config and avoid sending real mail from automated tests.

Deployment notes

Set RESEND_FROM to a verified domain sender. Treat mail delivery as an external side effect: trigger important mail from committed workflow state, usually through notifications, jobs, or outbox-backed listeners.

License

MIT

版本与发布记录

@beignet/provider-mail-resend 共发布 65 个版本,首次发布于 2026/05/27;过去 12 个月发布了 65 个版本。

版本发布日期距今
0.0.65latest2026/11/08今天
0.0.642026/11/034 天前
0.0.632026/11/026 天前
0.0.622026/11/017 天前
0.0.612026/11/017 天前
0.0.602026/11/017 天前

关于 @beignet/provider-mail-resend 的常见问题

@beignet/provider-mail-resend 是什么?

Resend mail provider for Beignet - adds mailer port using Resend

如何安装 @beignet/provider-mail-resend?

在项目目录运行 npm install @beignet/provider-mail-resend,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:resend(^6.14.0)、@beignet/core(>=0.0.3 <1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@beignet/provider-mail-resend 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beignet/provider-mail-resend 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@beignet/provider-mail-resend 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@beignet/provider-mail-resend 可以商用吗?

@beignet/provider-mail-resend 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@beignet/provider-mail-resend 的下载量有多少?

根据 npm 官方下载统计,@beignet/provider-mail-resend 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,897 次,日均约 63 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beignet/provider-mail-resend 还在维护吗?

最新版本 0.0.65 发布于 2026/11/08(今天);至今共发布 65 个版本,其中过去 12 个月发布了 65 个;首次发布于 2026/05/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。