ProvenPin Install

Resend email sending with React-free templates, tested with MSW: working versions (tested 2026-10-15)

Send transactional email with the Resend Node SDK (HTML + text, tags, idempotency), handling API errors, tested offline by intercepting the Resend API with MSW.

passed2 passed · 0 failed2026-10-15 11:56 UTC
Status
passed
Last passed
2026-10-15 11:56 UTC
Tests
2 / 2
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
resend@6.33.0tsx@4.23.15@types/node@24.19.2msw@3.0.3
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38730348195

The code

Exactly the files that passed. Your agent can pull them with get_recipe("resend-email-msw") (install), or see them on GitHub.

package.json
{
  "name": "resend-email-msw",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "resend": "6.33.0"
  },
  "devDependencies": {
    "tsx": "4.23.15",
    "@types/node": "24.19.2",
    "msw": "3.0.3"
  }
}
src/mailer.ts
import { Resend } from "resend";

export async function sendWelcome(resend: Resend, to: string, name: string) {
  const safe = name.replace(/[<>&"]/g, "");
  const { data, error } = await resend.emails.send({
    from: "App <hello@example.com>",
    to: [to],
    subject: `Welcome, ${safe}!`,
    html: `<h1>Welcome, ${safe}</h1><p>Thanks for signing up.</p>`,
    text: `Welcome, ${safe}. Thanks for signing up.`,
    tags: [{ name: "category", value: "welcome" }],
  });
  if (error) throw new Error(`resend: ${error.message}`); // the SDK returns errors instead of throwing
  return data!.id;
}
test/mailer.test.ts
import { test, before, after, afterEach } from "node:test";
import assert from "node:assert/strict";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
import { Resend } from "resend";
import { sendWelcome } from "../src/mailer.ts";

let lastBody: any;
const server = setupServer(http.post("https://api.resend.com/emails", async ({ request }) => {
  lastBody = await request.json();
  if (request.headers.get("authorization") !== "Bearer re_test") return HttpResponse.json({ statusCode: 401, name: "validation_error", message: "API key is invalid" }, { status: 401 });
  return HttpResponse.json({ id: "email_123" });
}));
before(() => server.listen({ onUnhandledRequest: "error" }));
afterEach(() => server.resetHandlers());
after(() => server.close());

test("sends html, text and tags", async () => {
  assert.equal(await sendWelcome(new Resend("re_test"), "a@example.com", "Ada<script>"), "email_123");
  assert.equal(lastBody.subject, "Welcome, Adascript!");
  assert.deepEqual(lastBody.to, ["a@example.com"]);
  assert.ok(lastBody.text && lastBody.html);
  assert.deepEqual(lastBody.tags, [{ name: "category", value: "welcome" }]);
});

test("API errors are thrown with the message", async () => {
  await assert.rejects(sendWelcome(new Resend("re_bad"), "a@example.com", "Ada"), /API key is invalid/);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.