Resend Email Sender Wrapper (lib/email.ts)

mobvibe · apps/gateway/src/lib/email.ts · typescript · Apache-2.0
email, infra, lang:typescript, tag:wrapper

Sends emails via Resend when an API key is configured; otherwise logs the email details for development environments.

// Source: https://github.com/Eric-Song-Nop/mobvibe | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { Resend } from "resend";
import { getGatewayConfig } from "../config.js";
import { logger } from "./logger.js";

const config = getGatewayConfig();

const resend = config.resendApiKey ? new Resend(config.resendApiKey) : null;

export type SendEmailOptions = {
	to: string;
	subject: string;
	text: string;
	html?: string;
};

/**
 * Send an email using Resend if configured, otherwise log to console.
 */
export async function sendEmail(options: SendEmailOptions): Promise<void> {
	const { to, subject, text, html } = options;

	if (!resend) {
		logger.info(
			{ to, subject, text

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

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

Get a free API key