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/nodemailerGet Up and Running in 3 Easy Steps
Install Nodemailer
Install `nodemailer` via npm or yarn into your Node.js or TypeScript backend project.
Configure SMTP credentials
Set host to `smtp.mailofly.com`, port to `587`, and your Mailofly API credentials in `.env`.
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.
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;
}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.
Explore Mailofly Infrastructure Capabilities
Build resilient, high-deliverability email systems with our core developer tools.
Frequently Asked Questions about Nodemailer
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.
