Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 5 min read

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 via STARTTLS before 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 filter 587.

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=spf1 TXT 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

  1. Always set requireTLS: true: Prevents credentials from ever leaking over plaintext if a proxy strips STARTTLS.
  2. Isolate Trigger vs. Batch credentials: 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:

  1. App log: Confirmed handshake + messageId returned (no 535 Authentication Failed or TLS errors).
  2. Provider delivery log: Look for terminal states (Delivered vs. Soft Bounce vs. Invalid Address).
  3. Recipient raw headers (Gmail โ†’ โ‹ฎ โ†’ Show original): Confirm all three say PASS:
    • SPF: PASS
    • DKIM: PASS (aligned with your sending domain)
    • DMARC: PASS

Common SMTP Errors Cheat Sheet

  • ETIMEDOUT / Connection refused โ†’ Port 25 or 587 blocked by cloud firewall. Try 465 or 2525 and confirm with openssl s_client.
  • 535 Authentication Failed โ†’ Wrong API_USER / API_KEY, or pasting a console login password instead of an SMTP token.
  • 550 Sender domain not verified โ†’ The From: 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?

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.