Skip to content

Mail

@veloxts/mail provides email sending with React templates.

Terminal window
pnpm add @veloxts/mail
import { mailPlugin } from '@veloxts/mail';
app.register(mailPlugin, {
driver: 'resend',
config: { apiKey: process.env.RESEND_API_KEY },
defaults: { from: 'hello@example.com' },
});
import { defineMail } from '@veloxts/mail';
import { Html, Body, Text } 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>
<Text>Click here to activate: {activationUrl}</Text>
</Body>
</Html>
),
});
await ctx.mail.send(WelcomeEmail, {
to: 'user@example.com',
data: { name: 'Alice', activationUrl: 'https://...' },
});
mailPlugin({
driver: 'smtp',
config: {
host: 'smtp.example.com',
port: 587,
auth: { user: '...', pass: '...' },
},
})
mailPlugin({
driver: 'resend',
config: { apiKey: process.env.RESEND_API_KEY },
})