Resend Mail Provider

This provider adds the official Resend SDK, validates RESEND_API_KEY with Zod, and exports a ready-to-use resend client.

Features

  • Minimal env surface: API key only (extend env.ts if you want a default from address)
  • Shared Resend instance
  • MVC and Feature architecture variants

Installation Guide

npx servercn-cli add pr resend-mail

File Structure

  • src/configs/env.ts
  • src/configs/resend.ts
  • src/shared/configs/env.ts
  • src/shared/configs/resend.ts

Environment Configuration

src/configs/env.ts
import "dotenv-flow/config";
import { z } from "zod";
 
export const envSchema = z.object({
  RESEND_API_KEY: z.string()
});
 
export type Env = z.infer<typeof envSchema>;
 
const result = envSchema.safeParse(process.env);
 
if (!result.success) {
  console.error("❌ Invalid environment configuration");
  console.error(z.prettifyError(result.error));
  process.exit(1);
}
 
export const env: Readonly<Env> = Object.freeze(result.data);
 
export default env;

Resend client

src/configs/resend.ts
import { Resend } from "resend";
import env from "./env";
 
export const resend = new Resend(env.RESEND_API_KEY);

Usage

Use a verified domain or Resend’s test sender for from.

import { resend } from "./configs/resend";
 
export async function sendWelcomeEmail(to: string) {
  const { data, error } = await resend.emails.send({
    from: "App <onboarding@resend.dev>",
    to,
    subject: "Welcome",
    html: "<p>Thanks for signing up.</p>"
  });
  if (error) throw error;
  return data;
}

To default the sender from env, add something like EMAIL_FROM: z.string() to envSchema alongside the API key (same pattern as the Nodemailer provider).

Example .env

RESEND_API_KEY=re_xxxxxxxx

File & Folder Structure

Loading files...

Installation

npx servercn-cli add provider resend-mail