Error codes
How API errors and SMTP replies are reported, and what to do about each kind.
API error format
API errors are JSON with a stable code and a message. Match on the code in your logic, and show the message only to people, since wording can change.
{
"error": { "code": "invalid_recipient", "message": "The recipient address is not valid." }
}Retry or fix?
Errors fall into two groups. Fix the request: 4xx responses other than 429 mean something is wrong with what you sent, so retrying will fail the same way. Try again later: 429 and 5xx responses are temporary, so retry with exponential backoff and a limit on attempts.
SMTP replies
SMTP replies start with a three-digit code. 2xx means success. 4xx means a temporary failure, so the sender should retry later. 5xx means a permanent failure, so do not retry the same message to that address. Many replies add an enhanced code such as 5.1.1 that explains the cause.
Reading bounce reasons
Enhanced codes are the quickest way to understand a bounce. 5.1.1 means the mailbox does not exist. 5.2.2 means the mailbox is full. 5.7.1 means the receiving server rejected the message on policy, often because of authentication or reputation. 4.x.x codes are temporary and will be retried.
What to do with bounces
Remove addresses that hard-bounce from your list, and investigate policy rejections by checking your SPF, DKIM and DMARC setup. A rising bounce rate harms your reputation, so act on it quickly.