EmailProvidersNodemailer

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 nodemailer

Setup

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:

OptionTypeRequiredDefaultDescription
transportRecord<string, unknown> | stringYes-Nodemailer transport configuration
defaultFromEmailAddressNo-Default from address
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance
retriesnumberNo3Number of retry attempts
timeoutnumberNo30000Request 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:

OptionTypeDescription
transportOverrideRecord<string, unknown> | stringOverride transport for this specific email

Supported Features

FeatureSupported
AttachmentsYes
Batch SendingNo
Custom HeadersYes
HTMLYes
Reply-ToYes
SchedulingNo
TaggingNo
TemplatesNo
TrackingNo
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues