Skip to main content

Idempotency Keys (SMTP)

Network glitches, timeouts, and connection drops during DATA can leave your sender unsure whether a message was actually accepted. Adding an X-Idempotency-Key MIME header lets you retry safely: a repeat with the same key and body is recognized as a duplicate, the original 250 reply is replayed, and no second message is queued or relayed.
Idempotency is currently scoped per region. A retry that lands on a different region than the original submission will not see the prior key and may produce a duplicate send. We are working on a global key store that will apply idempotency across all regions at once.

How it works

  1. Pick a unique key per logical send (a UUID v4 is a safe default).
  2. Add it as an X-Idempotency-Key MIME header inside the DATA payload.
  3. If the connection breaks before you read the reply, retry the SMTP transaction with the same key and same body. The server replays the original 250 response without sending a second email.
  4. If the same key is reused with a different body, the submission is rejected.
The X-Idempotency-Key header is stripped before delivery, so it never reaches recipients or appears on the relay leg.

Header reference

Keys are scoped per user. Pick something globally unique per logical send.

Example SMTP transaction

SMTP reply codes

A replay keeps the 250 status code so standard SMTP clients still treat the response as success, with the original queue id in the same position as on the first reply.

Retry over the same transport

JetEmail also accepts an Idempotency-Key header on the HTTP API. Always retry over the same transport you originally submitted on. A cross-transport retry (HTTP after SMTP, or vice versa) will not match and will produce a new send.

Best practices

  • Generate the key before the first attempt, not on retry, so retries can reuse it.
  • Persist the key alongside the work item that triggered the send (e.g. an order or job row) so the same retry path always reuses the same key.
  • One key per logical send. Do not reuse a key for unrelated emails.
  • Pair with scheduled sends when the SMTP submission that schedules a message may itself be retried.