Home/Integrations/Nodemailer
Node.js Universal SMTP Transport•Node.js Email Protocol

How to Configure Nodemailer with Mailofly SMTP Relay

Drop-in SMTP relay configuration for existing Node.js, Express, NestJS, and AdonisJS applications using Nodemailer with zero codebase refactoring.

npm install nodemailer && npm install -D @types/nodemailer
Setup Tutorial

Get Up and Running in 3 Easy Steps

01

Install Nodemailer

Install `nodemailer` via npm or yarn into your Node.js or TypeScript backend project.

02

Configure SMTP credentials

Set host to `smtp.mailofly.com`, port to `587`, and your Mailofly API credentials in `.env`.

03

Call transporter.sendMail()

Use the standard Nodemailer API to send transactional messages with automatic SPF/DKIM authentication.

Production-Ready Code Example

Copy and paste into your project. Fully typed and tested.

lib/nodemailer.ts
import nodemailer from "nodemailer";

// 1. Create reusable transporter using Mailofly SMTP relay
export const transporter = nodemailer.createTransport({
  host: process.env.MAILOFLY_SMTP_HOST || "smtp.mailofly.com",
  port: Number(process.env.MAILOFLY_SMTP_PORT) || 587,
  secure: false, // true for 465, false for 587
  auth: {
    user: process.env.MAILOFLY_API_KEY,
    pass: process.env.MAILOFLY_SECRET,
  },
});

// 2. Send transactional email
export async function sendEmail({
  to,
  subject,
  html,
}: {
  to: string;
  subject: string;
  html: string;
}) {
  const info = await transporter.sendMail({
    from: '"Support" <support@yourdomain.com>',
    to,
    subject,
    html,
  });

  console.log("Message sent: %s", info.messageId);
  return info;
}
Why Developers Love It

Engineered for Nodemailer

Zero Codebase Rewrites

If your legacy app already uses Nodemailer, swap your SMTP host and credentials in 60 seconds without refactoring any business logic.

Standard Port 587 & 465 Support

Support for both STARTTLS on port 587 and SSL/TLS on port 465 ensures seamless delivery across any cloud host or container.

Seamless REST SDK Upgrade Path

When moving to serverless platforms like Vercel, you can swap to @mailofly/node with identical payload arguments.

Got Questions?

Frequently Asked Questions about Nodemailer

Serverless platforms freeze execution immediately after returning a response and often block outbound TCP connections on port 25. For serverless deployments, we recommend using our HTTP SDK (@mailofly/node) or connecting via port 587 with keepAlive disabled.

Start Sending from Nodemailer in Minutes

3,000 free emails every month. Copy your API key, run the code snippet, and watch your delivery logs in real time.