NotifiersEmail (Nodemailer)

Nodemailer (Email)

The default notifier. Two modes: Ethereal (automatic test inbox, no config) or real SMTP (Gmail, Resend, SendGrid, etc.).

import { NodemailerNotifier, createAuth } from "guardo";
 
// No smtp config → auto-creates an Ethereal test account
const auth = createAuth({
  jwt: { secret: "..." },
  notifier: new NodemailerNotifier(),
});
// Outputs a preview URL to the console after sending

Without a buildHtml/buildText override, guardo sends a polished default email template. The default subject is "Your verification code".

EmailNotifierOptions

FieldTypeDefaultDescription
smtpSmtpConfig?-SMTP credentials. Omit to use Ethereal in dev.
fromstring?smtp user → Ethereal addressThe “From” address.
subjectstring?"Your verification code"Email subject line.
buildHtml(code, expiresInSeconds?) => stringbuilt-in templateCustom HTML body.
buildText(code, expiresInSeconds?) => stringauto-generatedCustom plain-text body.

SmtpConfig: { host: string; port?: number; secure?: boolean; user: string; pass: string } (port defaults to 587, secure to false).

⚠️

If Ethereal is unreachable (no internet / sandboxed CI), the notifier falls back to printing the OTP to the console so local flows don’t break.