Skip to main content

@adrper79-dot/email

Typed transactional email using Resend. Depends on @adrper79-dot/errors and @adrper79-dot/logger.

Installation

npm install @adrper79-dot/email

Secrets required

wrangler secret put RESEND_API_KEY

API

sendEmail(opts)

Sends a transactional email via Resend.
function sendEmail(opts: {
  apiKey: string;
  from: string;
  to: string | string[];
  subject: string;
  html: string;
  text?: string;
  replyTo?: string;
  tags?: Record<string, string>;
}): Promise<{ id: string }>;

renderTemplate(template, data)

Renders a named template with data interpolation.
function renderTemplate(
  template: EmailTemplate,
  data: Record<string, unknown>,
): { subject: string; html: string; text: string };

Built-in templates

TemplateUse case
welcomeNew user sign-up confirmation
subscription-createdPayment successful, plan started
subscription-canceledSubscription ended
trial-endingTrial expires in N days
password-resetPassword reset link

Example

import { sendEmail, renderTemplate } from '@adrper79-dot/email';

const { subject, html, text } = renderTemplate('welcome', {
  firstName: 'Jane',
  appName: 'FocusBro',
  loginUrl: 'https://focusbro.app/login',
});

await sendEmail({
  apiKey: env.RESEND_API_KEY,
  from: 'hello@focusbro.app',
  to: user.email,
  subject,
  html,
  text,
});