Nodemailer
Send emails using the Nodemailer library with @visulima/email
Nodemailer Provider
The Nodemailer provider wraps the popular Nodemailer Node.js email library, allowing you to use any Nodemailer transport (SMTP, Sendmail, SES, etc.) with the @visulima/email API.
Runtime Support: Node.js only (requires the nodemailer package)
Prerequisites
Install nodemailer as a peer dependency:
npm install nodemailerSetup
SMTP Transport
import { createMail } from "@visulima/email";
import { nodemailerProvider } from "@visulima/email/providers/nodemailer";
const mail = createMail(
nodemailerProvider({
transport: {
host: "smtp.example.com",
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USER!,
pass: process.env.SMTP_PASSWORD!,
},
},
}),
);Sendmail Transport
const mail = createMail(
nodemailerProvider({
transport: {
sendmail: true,
path: "/usr/sbin/sendmail",
},
}),
);Configuration
The NodemailerConfig interface extends BaseConfig with the following options:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
transport | Record<string, unknown> | string | Yes | - | Nodemailer transport configuration |
defaultFrom | EmailAddress | No | - | Default from address |
debug | boolean | No | false | Enable debug logging |
logger | Console | No | - | Custom logger instance |
retries | number | No | 3 | Number of retry attempts |
timeout | number | No | 30000 | Request timeout in milliseconds |
The transport option accepts any valid Nodemailer transport configuration. See Nodemailer transports documentation for all available options.
Basic Usage
import { MailMessage } from "@visulima/email";
const message = new MailMessage()
.to("user@example.com")
.from("sender@example.com")
.subject("Hello via Nodemailer")
.html("<h1>Hello World</h1>");
const result = await mail.send(message);Provider-Specific Email Options
The Nodemailer provider supports additional options through NodemailerEmailOptions:
| Option | Type | Description |
|---|---|---|
transportOverride | Record<string, unknown> | string | Override transport for this specific email |
Supported Features
| Feature | Supported |
|---|---|
| Attachments | Yes |
| Batch Sending | No |
| Custom Headers | Yes |
| HTML | Yes |
| Reply-To | Yes |
| Scheduling | No |
| Tagging | No |
| Templates | No |
| Tracking | No |