guides
Nodemailer SMTP Guide (Node.js Send + Receive Test Workflow)
Configure Nodemailer SMTP in Node.js with environment-based settings, troubleshooting guidance, and deterministic inbox testing patterns.
If you searched for nodemailer smtp, this guide covers:
- transport configuration with secure defaults
- environment-based credential management
- common Node SMTP failure patterns
- inbox-assertion testing in CI
Minimal Nodemailer SMTP setup
npm install nodemailer
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT || 587),
secure: false,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});
async function sendWelcomeEmail(to) {
await transporter.sendMail({
from: process.env.SMTP_FROM_ADDRESS,
to,
subject: "Welcome",
text: "Your account is ready.",
});
}
SMTP configuration defaults to standardize
For stable releases, document and enforce:
- host and port per environment
- TLS mode (
587STARTTLS vs465implicit TLS) - sender address policy and domain alignment
- timeout/retry behavior for transient failures
Related references:
Common Nodemailer SMTP failures
EAUTH or SMTP 535 errors
Likely causes:
- wrong credentials
- auth mechanism mismatch
- sender-domain policy mismatch
Connection and timeout failures
Likely causes:
- blocked outbound network path
- wrong port/TLS combination
- DNS/hostname issues
Sent response but no inbox arrival
Likely causes:
- spam placement
- sender reputation/authentication posture
- mailbox filtering rules
Add receive-side verification to Node test suites
SMTP send success is not enough. Also assert:
- message arrival
- expected subject/body
- link and OTP correctness
- timing/SLA behavior
Recommended testing routes:
Nodemailer SMTP production checklist
- Keep SMTP credentials and sender settings in environment variables.
- Validate SPF, DKIM, and DMARC before releasing sender changes.
- Add inbox assertions for critical user journeys.
- Capture delivery and failure events for triage.
- Re-test after template, DNS, or provider changes.
FAQ
Is Nodemailer enough for production SMTP?
Yes, if paired with configuration discipline, inbox testing, and deliverability monitoring.
Should Nodemailer use port 587?
Usually yes with STARTTLS, but always use provider-specific settings and validate in each environment.
Can Nodemailer be used for receive-side inbox checks?
Nodemailer is for sending. Use inbox APIs and test infrastructure for receive-side assertions.