Skip to main content
Nodemailer is a popular Node.js library for sending emails.
In this guide, you’ll learn how to configure it with thePurplebox SMTP service to send transactional emails reliably and securely.

Prerequisites

Before getting started, make sure your project has:
  • Nodemailer installed
  • A thePurplebox SMTP password (API key) stored in your .env file
  • A verified sending domain (recommended for best deliverability)

Install Nodemailer

Optional: Install Nodemailer TypeScript types

If your project uses TypeScript, install the types as well:

Set up environment variables

Store your SMTP password securely in a .env file:
.env
Note: The SMTP username is always: thepurplebox

Sending Transactional Emails

Once Nodemailer and your environment variables are set up, you can create a transporter. This object defines the SMTP connection settings and determines whether you use STARTTLS or SSL.

Using STARTTLS (Port 587)

Set secure to false and use port 587:

Using SSL (Port 465)

Set secure to true and use port 465:

Sending an Email

Now that the transporter is configured, you can send your first email with thePurplebox:
Or use a try/catch for better error handling: