Prompt
how to send transactional email from node
Latest observation
Nov 6, 2026
OpenAI APIWeb search: off
To send transactional email from Node.js, you typically use an email service provider like SendGrid, Mailgun, Amazon SES, Postmark, or Resend. These handle deliverability and let you send via an API or SMTP.
Common approach: use a provider SDK
Example with Nodemailer + SMTP
If you already have SMTP credentials, nodemailer is the simplest:
npm install nodemailer
const nodemailer = require("nodemailer");
async function sendEmail() {
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com", // or your provider SMTP host
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
const info = await transporter.sendMail({
from: '"Your App" <no-reply@yourdomain.com>',
to: "user@example.com",
subject: "Welcome!",
text: "Thanks for signing up.",
html: "<p>Thanks for signing up.</p>",
});
console.log("Message sent:", info.messageId);
}
sendEmail().catch(console.error);
Example with a transactional email API
Most providers also offer direct API clients.
SendGrid
npm install @sendgrid/mail
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
async function sendEmail() {
await sgMail.send({
to: "user@example.com",
from: "no-reply@yourdomain.com",
subject: "Password reset",
text: "Click the link to reset your password.",
html: "<p>Click the link to reset your password.</p>",
});
}
sendEmail().catch(console.error);
Recommended setup for transactional email
- Use a verified domain (
no-reply@yourdomain.com) - Set up SPF, DKIM, and DMARC
- Use a provider designed for transactional mail
- Separate transactional mail from marketing mail
- Handle errors/retries gracefully
If you want the easiest path
For most Node apps, I’d recommend:
- Resend for simplicity
- Postmark for excellent transactional delivery
- SendGrid for general flexibility
- Amazon SES for low cost at scale
If you want, I can give you a ready-to-use example for Express, NestJS, or Next.js, or show you how to set it up with Resend/Postmark/SendGrid.