Log
Console output for development and testing.
@veloxts/mail provides email sending with type-safe React Email templates, supporting SMTP and Resend.
pnpm add @veloxts/mail
# For Resend (recommended)pnpm add resendimport { mailPlugin } from '@veloxts/mail';
// Log driver - prints to consoleapp.register(mailPlugin({ driver: 'log', from: { name: 'My App', email: 'noreply@myapp.com' },}));import { mailPlugin } from '@veloxts/mail';
app.register(mailPlugin({ driver: 'resend', config: { apiKey: process.env.RESEND_API_KEY, }, from: { name: 'My App', email: 'noreply@myapp.com' },}));import { mailPlugin } from '@veloxts/mail';
app.register(mailPlugin({ driver: 'smtp', config: { host: process.env.SMTP_HOST, port: parseInt(process.env.SMTP_PORT || '587'), secure: process.env.SMTP_SECURE === 'true', auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS, }, }, from: { name: 'My App', email: 'noreply@myapp.com' },}));import { defineMail } from '@veloxts/mail';import { z } from 'zod';import { Html, Body, Text, Button } from '@react-email/components';
export const WelcomeEmail = defineMail({ name: 'welcome', schema: z.object({ name: z.string(), activationUrl: z.string().url(), }), subject: ({ name }) => `Welcome, ${name}!`, template: ({ name, activationUrl }) => ( <Html> <Body> <Text>Hello {name}!</Text> <Button href={activationUrl}>Activate Account</Button> </Body> </Html> ),});// Basic sendawait ctx.mail.send(WelcomeEmail, { to: 'user@example.com', data: { name: 'Alice', activationUrl: 'https://...' },});
// With CC/BCCawait ctx.mail.send(WelcomeEmail, { to: 'user@example.com', cc: ['manager@example.com'], bcc: ['archive@example.com'], data: { ... },});
// With attachmentsawait ctx.mail.send(InvoiceEmail, { to: 'user@example.com', data: { invoice }, attachments: [ { filename: 'invoice.pdf', content: pdfBuffer }, ],});Log
Console output for development and testing.
Resend
Modern API with React Email integration.
SMTP
Traditional SMTP for any provider.
| Provider | Best For |
|---|---|
| Resend | Simple API, React Email native |
| AWS SES | High volume, cost-effective |
| SendGrid | Enterprise features |
| Postmark | Transactional focus |
RESEND_API_KEY=re_xxxxxxxxxxxxSMTP_HOST=smtp.example.comSMTP_PORT=587SMTP_SECURE=falseSMTP_USER=your-usernameSMTP_PASS=your-password@veloxts/queue for background sendingDon’t block requests with email sending:
const sendEmailJob = defineJob({ name: 'email.send', schema: z.object({ template: z.string(), to: z.string().email(), data: z.record(z.unknown()), }), handler: async ({ data, ctx }) => { const template = templates[data.template]; await ctx.mail.send(template, { to: data.to, data: data.data }); },});
// Dispatch instead of sending directlyawait ctx.queue.dispatch(sendEmailJob, { template: 'welcome', to: 'user@example.com', data: { name: 'Alice', activationUrl: '...' },});