Skip to content

Mail

Mail

The mail module provides a consistent API for sending email regardless of which delivery service you use. Switch between SMTP, Resend, Postmark, or the console driver without changing any of your application code.

Import

import { createMail } from '@loewen-digital/fullstack/mail'

Basic usage

import { createMail } from '@loewen-digital/fullstack/mail'
const mail = createMail({
driver: 'smtp',
from: { name: 'My App', address: 'hello@example.com' },
smtp: {
host: process.env.SMTP_HOST!,
port: 587,
auth: { user: process.env.SMTP_USER!, pass: process.env.SMTP_PASS! },
},
})
await mail.send({
to: 'alice@example.com',
subject: 'Welcome to My App',
text: 'Thanks for signing up!',
html: '<p>Thanks for signing up!</p>',
})

Sending to multiple recipients

await mail.send({
to: ['alice@example.com', 'bob@example.com'],
cc: 'manager@example.com',
bcc: 'archive@example.com',
subject: 'Team update',
text: 'Here is the weekly update...',
})

Attachments

await mail.send({
to: 'alice@example.com',
subject: 'Your invoice',
text: 'Please find your invoice attached.',
attachments: [
{
filename: 'invoice-2026-04.pdf',
content: pdfBytes, // Uint8Array
contentType: 'application/pdf',
},
],
})

Development: console driver

Use the console driver in development to see emails in your terminal without sending them:

const mail = createMail({
driver: process.env.NODE_ENV === 'production' ? 'resend' : 'console',
from: { name: 'My App', address: 'hello@example.com' },
resend: { apiKey: process.env.RESEND_API_KEY! },
})

Driver options

DriverDescription
consolePrints emails to stdout. No external service needed.
smtpStandard SMTP. Works with any SMTP server.
resendResend API. Requires resend npm package.
postmarkPostmark API. Requires postmark npm package.

Config options

OptionTypeDefaultDescription
driver'console' | 'smtp' | 'resend' | 'postmark'Mail driver
from.namestringDefault sender name
from.addressstringDefault sender email address
smtp.hoststringSMTP server hostname
smtp.portnumber587SMTP server port
smtp.auth.userstringSMTP username
smtp.auth.passstringSMTP password
resend.apiKeystringResend API key
postmark.serverTokenstringPostmark server token