SMTP
Send emails via SMTP with Nodemailer
The SMTP transport is an official Better-Notify package backed by Nodemailer. Use it when your provider gives you SMTP credentials and you want a straightforward way to send Better-Notify email routes.
It is a thin delivery adapter. Better-Notify handles rendering and validation upstream; smtpTransport() only turns the rendered email into a Nodemailer sendMail() call.
Install
npm install @betternotify/smtp @betternotify/core @betternotify/emailUsage
import { createNotify, createClient } from '@betternotify/core';
import { emailChannel } from '@betternotify/email';
import { smtpTransport } from '@betternotify/smtp';
const email = emailChannel({
defaults: { from: { name: 'My App', email: 'noreply@example.com' } },
});
const rpc = createNotify({ channels: { email } });
const catalog = rpc.catalog({
/* routes */
});
const mail = createClient({
catalog,
transportsByChannel: {
email: smtpTransport({
host: 'smtp.example.com',
port: 587,
auth: {
user: process.env.SMTP_USER!,
pass: process.env.SMTP_PASS!,
},
}),
},
});For implicit TLS on port 465, set secure: true:
import { smtpTransport } from '@betternotify/smtp';
const transport = smtpTransport({
host: 'smtp.example.com',
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER!,
pass: process.env.SMTP_PASS!,
},
});Common options
Prop
Type
From address behavior
If message.from is missing, the transport falls back to auth.user. If neither is set, Better-Notify throws a CONFIG error.
Some SMTP providers rewrite the From address to match the authenticated user. When that happens, Better-Notify logs a one-time warning for each mismatching address. If you want the visible sender to stay unchanged, align defaults.from with auth.user or switch to a provider that accepts your verified sender address as-is.
Sending limits
SMTP is a thin transport. It does not rate-limit, retry, or fail over for you.
Before using it in production, check your provider's limits for:
- sends per second or minute
- daily volume
- concurrent connections
- sandbox or trial restrictions
If you need throttling or provider fallback, add middleware such as withRateLimit or wrap SMTP in multiTransport({ strategy: 'failover' }).