Classify an SMTP reply
Read the reply code and enhanced status code, and tell a temporary failure from a permanent one.
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.
Keep exploring
- Convert an email domain to punycode — Keep the local part and convert an international domain to its ASCII xn-- form.
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.