Skip to content

Email System

The Email System decouples the intent to send an email from the actual template implementation.

Modules register React components to handle specific email “intents” (e.g., user:welcome).

modules/user/src/emails/init.ts
import { EmailRegistry } from '@/lib/email/email-registry';
import WelcomeEmail from './WelcomeEmail';
EmailRegistry.register('user:welcome', WelcomeEmail);

The sender renders the template by ID.

import { EmailRegistry } from '@/lib/email/email-registry';
import { sendEmail } from '@/lib/email/email-sender';
const html = await EmailRegistry.render('user:welcome', { name: 'Alice' });
await sendEmail({ to: '[email protected]', subject: 'Welcome', html });