Port 25 Blocked, 250 OK Isn't Delivery: A Practical Guide to Production SMTP Relay Setup (Node.js + DNS)
Every backend developer eventually learns the same lesson the hard way: sending email directly from your application server looks easy on localhost and fails silently in production. You deploy to AWS, GCP, or DigitalOce
Every backend developer eventually learns the same lesson the hard way: sending email directly from your application server looks easy on localhost and fails silently in production.
You deploy to AWS, GCP, or DigitalOcean. Outbound TCP port 25 is blocked at the hypervisor level. Even if you get port 25 opened, your fresh VM IP has zero sending reputationโor worse, it inherited a blocklist record from whoever leased that IP last month. Password resets either time out or land straight in Gmail's spam folder.
This guide walks through the exact mechanics of switching an app to a hosted SMTP relay, how to wire it up cleanly in Node.js, and the three debugging checks that actually prove your email reached an inbox (spoiler: SMTP 250 OK is not one of them).
1. SMTP Relay vs. REST Email API: Don't Over-Engineer the Wrong One
Before writing code, pick the transport that fits your codebase:
| Requirement | Use SMTP Relay | Use HTTP Email API |
|---|---|---|
| Existing app (WordPress, Grafana, Keycloak, legacy CRM) | Best fit โ drop-in config, zero code change | Requires custom plugin or rewrite |
| High-throughput microservices / parallel sends | Slower (chatty multi-roundtrip handshake) | Best fit โ single HTTPS POST |
| Rich per-recipient metadata & webhook events | Limited (needs provider headers like X-SMTPAPI) |
Best fit โ native JSON payloads |
| Restrictive corporate / cloud firewalls | Works on 587, 465, or 2525
|
Works on standard HTTPS 443
|
If you maintain legacy tools and modern services, pick a provider that exposes both SMTP and REST under the same verified domain (e.g., Postmark, Mailgun, Amazon SES, or EngageLab).
2. Which Port Should You Actually Use?
Forget port 25 for app-to-relay submission. Here is what matters in 2026:
-
Port
587(STARTTLS) โ Default choice: Starts plain, immediately upgrades to TLS viaSTARTTLSbefore credentials are sent. Supported almost everywhere. -
Port
465(Implicit TLS): Wraps the socket in TLS from byte zero. Slightly fewer downgrade edge cases; also widely supported. -
Port
2525(Fallback): Not an IANA standard, but offered by many relays specifically for cloud/PaaS environments that filter587.
You can verify reachability from your production container in two seconds before blaming your app code:
# Test STARTTLS handshake on port 587
openssl s_client -starttls smtp -connect smtp.engagelab.cc:587 -crlf -quiet
# Or test implicit TLS on port 465
openssl s_client -connect smtp.engagelab.cc:465 -crlf -quiet
If this hangs until timeout, it is a firewall / security-group blockโnot an authentication bug.
3. DNS Checklist Before Sending a Single Test Email
Most "my SMTP relay lands in spam" threads boil down to half-finished DNS recordsโespecially after Googleโs bulk email sender requirements tightened SPF, DKIM, and DMARC enforcement. Use a dedicated subdomain (like mail.yourdomain.com) so transactional traffic doesn't pollute your root domain's corporate email reputation.
Verify all four records with dig before going live:
# 1. SPF (authorizes the relay to send for your domain)
dig TXT mail.yourdomain.com +short
# 2. DKIM (cryptographic signature โ replace selector with your provider's value)
dig TXT default._domainkey.mail.yourdomain.com +short
# 3. MX (required by several relays for domain verification & bounce routing)
dig MX mail.yourdomain.com +short
# 4. DMARC (tells Gmail/Yahoo what to do when SPF/DKIM fail)
dig TXT _dmarc.yourdomain.com +short
Tip: Never publish two separate
v=spf1TXT records on the same hostโreceiving servers treat multiple SPF records as a permanent error (PermError) and fail SPF completely. Merge mechanisms into one record instead.
4. Clean Node.js Implementation (nodemailer)
Here is a minimal, production-safe Nodemailer setup using STARTTLS on port 587 and connection pooling.
In this example we use EngageLab's Singapore SMTP endpoint (smtp.engagelab.cc, which also offers smtp-tr.engagelab.com for Tรผrkiye and a 50/day free tier for dev testing), but the exact same pattern works for Postmark, Mailgun, or Amazon SESโjust swap the host and credentials:
import nodemailer from "nodemailer";
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || "smtp.engagelab.cc",
port: Number(process.env.SMTP_PORT || 587),
secure: false, // false for 587 (STARTTLS), true for 465 (implicit TLS)
requireTLS: true, // refuse to send if STARTTLS upgrade fails
pool: true,
maxConnections: 5,
auth: {
user: process.env.SMTP_API_USER, // Separate Trigger vs. Batch credentials
pass: process.env.SMTP_API_KEY,
},
});
export async function sendPasswordReset(to, resetUrl) {
const info = await transporter.sendMail({
from: '"App Security" <[email protected]>',
to,
subject: "Reset your password",
text: `Use this link within 15 minutes: ${resetUrl}`,
html: `<p>Use this link within 15 minutes:</p><p><a href="${resetUrl}">Reset Password</a></p>`,
});
console.log("Relay accepted message:", info.messageId);
return info;
}
Two Details Worth Getting Right Early
-
Always set
requireTLS: true: Prevents credentials from ever leaking over plaintext if a proxy stripsSTARTTLS. -
Isolate
Triggervs.Batchcredentials: Create separate SMTP users/streams for transactional alerts vs. marketing blasts. If bulk traffic triggers complaints, your password resets keep delivering.
5. Stop Trusting 250 OK โ Verify Three Layers Instead
Seeing 250 OK in your Node.js logs only proves your relay accepted the payload into its outbound queue. It does not prove Gmail or Outlook accepted it.
After your first real send, check all three:
-
App log: Confirmed handshake +
messageIdreturned (no535 Authentication Failedor TLS errors). -
Provider delivery log: Look for terminal states (
Deliveredvs.Soft Bouncevs.Invalid Address). -
Recipient raw headers (Gmail โ
โฎโ Show original): Confirm all three sayPASS:SPF: PASS-
DKIM: PASS(aligned with your sending domain) DMARC: PASS
Common SMTP Errors Cheat Sheet
-
ETIMEDOUT/ Connection refused โ Port25or587blocked by cloud firewall. Try465or2525and confirm withopenssl s_client. -
535 Authentication Failedโ WrongAPI_USER/API_KEY, or pasting a console login password instead of an SMTP token. -
550 Sender domain not verifiedโ TheFrom:address domain doesn't match your verified DNS domain (SPF/DKIM/MX still pending). -
Lands in Spam despite
250 OKโ Missing DMARC, broken DKIM alignment, or mixing bulk and transactional mail on one IP/stream.
If you want a deeper breakdown of how 6 major relays (SendGrid, EngageLab, Mailgun, Postmark, Amazon SES, and Brevo) compare on ports, regions, and limits, here is the full reference guide: SMTP Relay Service: How It Works, Providers & Setup.
What SMTP relay or Email API is your team running in 2026โand have you hit any weird cloud port blocks lately?
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.