Classify an SMTP reply

Read the reply code and enhanced status code, and tell a temporary failure from a permanent one.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

classify-an-smtp-reply.js
function classifySmtpReply(reply) { const [, code, enhanced] = /^([2-5]\d{2})(?:[ -]([245]\.\d{1,3}\.\d{1,3}))?/.exec(reply); return { code: Number(code), enhanced: enhanced || null, outcome: { 2: 'success', 3: 'intermediate', 4: 'transient', 5: 'permanent' }[code[0]], retry: code[0] === '4' }; }

Input & expected output

Input

"550 5.1.1 The email account that you tried to reach does not exist"

Expected output

{
  "code": 550,
  "enhanced": "5.1.1",
  "outcome": "permanent",
  "retry": false
}

The edge case

Input

"451 4.7.1 Try again later"

Expected output

{
  "code": 451,
  "enhanced": "4.7.1",
  "outcome": "transient",
  "retry": true
}

Know the limits

  • Reply classes follow RFC 5321: 2xx success, 3xx intermediate, 4xx transient, 5xx permanent. Enhanced codes (RFC 3463, class.subject.detail) refine the reason; servers may omit them.
  • The sending server retries transient replies, not your application. With Oveyon, act on the per-recipient state it reports — such as deferred or bounced — instead of parsing SMTP text yourself.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.

The function above is the implementation the lab runs and the tests exercise. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.