Getting started
Idempotency
Retry requests safely without sending duplicate emails.
Network errors and timeouts happen. To retry a send without risking a duplicate email, include an Idempotency-Key header:
curl -X POST https://stackemails.com/v1/emails \
-H "Authorization: Bearer $STACKEMAILS_API_KEY" \
-H "Idempotency-Key: welcome-email/user_123" \
-H "Content-Type: application/json" \
-d '{ "from": "...", "to": "...", "subject": "...", "html": "..." }'
If a request with the same key has already been accepted, the API returns the original email (status 200 instead of 202) and does not send again.
- Keys are scoped to your team and can be up to 256 characters.
- Derive them from the event that triggers the email, e.g.
order-receipt/ord_789. - For batch sends, the key applies to the whole batch; each item uses
<key>:<index>.
With the SDK:
await stack.emails.send({ from, to, subject, html, idempotencyKey: `welcome/${user.id}` });