getResend (lib/email-utils.ts)

careercompass · src/lib/email-utils.ts · typescript · MIT
email, tag:knn-classified

Utility functions for sending transactional emails via Resend with rate limiting.

// Source: https://github.com/arsh342/careercompass | License: MIT | Copyright 2025 arsh342
// Provided via justclaw.it.com; keep this notice with the code.
"use server";

import { Resend } from "resend";
import { adminDb } from "@/lib/firebase-admin";
import { FieldValue } from "firebase-admin/firestore";
import { requireServerAuthenticatedUser, requireServerRole } from "@/lib/server-auth";

// Lazy initialization to avoid client-side errors
let resend: Resend | null = null;
export async function getResend(): Promise<Resend> {
  if (!resend) {
    resend = new Resend(process.env.RESEND_API_KEY);
  }
  return resend;
}

export interface EmailInput {
  to: string;
  subject: string;
  body: string;
}

export interface EmailDeliveryStatus {
  messageId: string;
  status: "sent" | "delivered"

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key