Back to results for “Background Jobs & Queues”
Node.js › Email & Notifications

What is Nodemailer, and how does it let a Node.js application send emails via SMTP?

Beginner

Answer

Nodemailer is the most widely used Node.js library for sending email, supporting SMTP (talking directly to a mail server or provider like Gmail, SendGrid, or Amazon SES over the standard email protocol) as well as several transport methods -- it handles the details of MIME message formatting, attachments, and HTML/plain-text bodies behind a simple, promise-based API.
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: 'smtp.sendgrid.net',
  port: 587,
  auth: { user: 'apikey', pass: process.env.SENDGRID_API_KEY },
});

await transporter.sendMail({
  from: 'noreply@example.com',
  to: user.email,
  subject: 'Welcome!',
  html: '<h1>Welcome to our platform</h1>',
});
Real-world example A SaaS application uses Nodemailer configured with SendGrid's SMTP relay to send transactional emails like welcome messages and password resets, relying on SendGrid's infrastructure for actual delivery rather than managing its own mail server.

Common follow-ups: Why do most production applications use a third-party email provider (SendGrid, SES) rather than sending directly from their own server via SMTP?;How would you handle and log a failed email send without blocking the request that triggered it?