@fabrk/email
v0.3.1
Published
Email adapters for FABRK framework (Resend, console)
Maintainers
Readme
@fabrk/email
Email adapters and templates for the FABRK framework. Supports Resend for production and a console adapter for development.
Installation
npm install @fabrk/emailUsage
import { createResendAdapter } from '@fabrk/email'
const email = createResendAdapter({
apiKey: process.env.RESEND_API_KEY!,
from: '[email protected]',
})
await email.send({
to: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome to the app</h1>',
})Console Adapter (Development)
import { createConsoleAdapter } from '@fabrk/email'
const email = createConsoleAdapter({ logHtml: true })
// Logs email details to console instead of sending
await email.send({
to: '[email protected]',
subject: 'Test email',
html: '<p>This prints to your terminal</p>',
})Templates
Four built-in templates are included. Send them with sendTemplate:
await email.sendTemplate('[email protected]', {
template: 'welcome',
data: { name: 'Alice', appName: 'MyApp', dashboardUrl: '/dashboard' },
})
await email.sendTemplate('[email protected]', {
template: 'verification',
data: { name: 'Alice', verificationUrl: 'https://app.com/verify?token=abc' },
})Custom Templates
Register your own templates with registerTemplate:
import { registerTemplate } from '@fabrk/email'
registerTemplate('billing', (data) => ({
subject: `Invoice #${data.invoiceId}`,
html: `<p>Your invoice for $${data.amount} is ready.</p>`,
}))
await email.sendTemplate('[email protected]', {
template: 'billing',
data: { invoiceId: '1234', amount: '29.99' },
})Features
- Resend Adapter - Production email delivery via the Resend API with support for CC, BCC, reply-to, headers, and tags
- Console Adapter - Logs emails to the terminal for local development; always available with no configuration
- Template System -
renderTemplaterenders named templates with data;registerTemplateadds custom templates at runtime - Built-in Templates - Verification, password reset, welcome, and team invite templates with monospace terminal styling
- Adapter Pattern - Both adapters implement the
EmailAdapterinterface from@fabrk/corefor consistent swapping between environments
Documentation
License
MIT
