npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contract-kit/provider-mail-resend

v0.1.1

Published

Resend mail provider for contract-kit - adds mailer port using Resend

Downloads

116

Readme

@contract-kit/provider-mail-resend

Resend mail provider for contract-kit that extends your application ports with email sending capabilities using Resend.

Installation

npm install @contract-kit/provider-mail-resend resend
# or
bun add @contract-kit/provider-mail-resend resend

TypeScript Requirements

This package requires TypeScript 5.0 or higher for proper type inference.

Usage

Basic Setup

import { createServer } from "@contract-kit/server";
import { mailResendProvider } from "@contract-kit/provider-mail-resend";

// Set environment variables:
// RESEND_API_KEY=re_...
// RESEND_FROM="My App <[email protected]>"

const app = createServer({
  ports: basePorts,
  providers: [mailResendProvider],
  createContext: ({ ports }) => ({
    ports,
    // ... other context
  }),
  routes: [
    // ... your routes
  ],
});

Sending Emails in Use Cases

Once the provider is registered, your ports will include a mailer property:

// Send plain text email
async function sendWelcomeEmail(ctx: AppCtx, user: User) {
  await ctx.ports.mailer.sendText(
    user.email,
    "Welcome!",
    "Thank you for signing up!"
  );
}

// Send HTML email
async function sendPasswordReset(ctx: AppCtx, user: User, resetLink: string) {
  await ctx.ports.mailer.sendHtml(
    user.email,
    "Password Reset",
    `<h1>Reset Your Password</h1>
     <p>Click <a href="${resetLink}">here</a> to reset your password.</p>`
  );
}

// Send with full options
async function sendCustomEmail(ctx: AppCtx) {
  await ctx.ports.mailer.send({
    from: "[email protected]", // Override default sender
    to: "[email protected]",
    subject: "Custom Email",
    html: "<h1>Hello!</h1>",
  });
}

Configuration

The Resend provider reads configuration from environment variables with the RESEND_ prefix:

| Variable | Required | Description | Example | |----------|----------|-------------|---------| | RESEND_API_KEY | Yes | Resend API key | re_abc123... | | RESEND_FROM | Yes | Default sender email address (must be from verified domain) | "My App <[email protected]>" |

Getting an API Key:

  1. Sign up at resend.com
  2. Verify your domain
  3. Create an API key at resend.com/api-keys

Mailer Port API

The provider extends your ports with the following mailer interface:

sendText(to: string, subject: string, text: string): Promise<void>

Send a plain text email using the default sender address.

await ctx.ports.mailer.sendText(
  "[email protected]",
  "Welcome",
  "Thanks for joining!"
);

sendHtml(to: string, subject: string, html: string): Promise<void>

Send an HTML email using the default sender address.

await ctx.ports.mailer.sendHtml(
  "[email protected]",
  "Welcome",
  "<h1>Thanks for joining!</h1>"
);

send(options: SendTextOptions | SendHtmlOptions): Promise<void>

Send an email with full control over options, including the ability to override the sender.

await ctx.ports.mailer.send({
  from: "[email protected]", // Optional sender override
  to: "[email protected]",
  subject: "Hello",
  html: "<p>Custom email</p>",
});

client: Resend

Access the underlying Resend client for advanced operations.

// Use Resend features directly
const { data, error } = await ctx.ports.mailer.client.emails.send({
  from: "[email protected]",
  to: ["[email protected]", "[email protected]"],
  subject: "Bulk Email",
  html: "<p>Message to multiple recipients</p>",
  tags: [
    { name: "category", value: "newsletter" },
  ],
  attachments: [
    {
      filename: "document.pdf",
      content: pdfBuffer,
    },
  ],
});

TypeScript Support

To get proper type inference for the mailer port, extend your ports type:

import type { MailerPort } from "@contract-kit/mail";
import type { Resend } from "resend";

// Your base ports
const basePorts = definePorts({
  db: dbAdapter,
});

// After using mailResendProvider, your ports will have this shape:
type AppPorts = typeof basePorts & {
  mailer: MailerPort<Resend>;
};

Lifecycle

The Resend Mail provider:

  1. During register:
    • Creates Resend client with API key
    • Adds the mailer port
  2. During onAppStop: No cleanup needed (Resend client is stateless)

Error Handling

The provider will throw errors in these cases:

  • Missing required environment variables
  • Invalid API key
  • Invalid email addresses
  • Domain not verified in Resend

Make sure to handle these during application startup.

Comparing with SMTP Provider

Resend offers several advantages over traditional SMTP:

  • Simpler setup: Just an API key, no SMTP server configuration
  • Better deliverability: Resend handles infrastructure and reputation
  • Modern features: Built-in analytics, webhooks, and templates
  • No port/firewall issues: Uses HTTPS instead of SMTP ports

Use the SMTP provider (@contract-kit/provider-mail-smtp) if you need to:

  • Use your existing SMTP server
  • Have strict data residency requirements
  • Integrate with legacy email systems

License

MIT