Sending Email from Node with Nodemailer
Deliver welcome messages, password resets, and notifications from your Node backend
- create an SMTP transport and send your first message with
sendMail(); - build a message object with
to,from,subject, and bothtextandhtmlbodies; - attach files and embed inline images with
cid; - keep SMTP credentials out of your code using environment config;
- test sends during development without spamming real inboxes.
1. What "transactional email" means
There are two broad kinds of email a backend sends. Marketing email (newsletters, promotions) goes to many recipients at once and is usually handled by a dedicated platform. Transactional email is different: it is a single message sent to one person because of something they just did. A user registers, so you send a welcome email. A user clicks "forgot password", so you send a reset link. An order ships, so you send a confirmation. These are the messages Nodemailer is perfect for.
Analogy. Think of your application as a busy office. Transactional email is the office assistant who, the instant a form lands on the desk, writes a tidy reply and drops it in the outgoing mail tray. Nodemailer is that assistant: you hand it the details of one letter, and it formats the envelope, addresses it, and passes it to the postal service (the SMTP server) for delivery.
Nodemailer itself does not deliver mail across the internet — that is the job of an SMTP server (Simple Mail Transfer Protocol). Nodemailer's job is to build a correct message and speak SMTP to a server you choose, whether that is Gmail, a company mail server, or a provider such as SendGrid, Mailgun, or Amazon SES exposed over SMTP.