Guides
Retry queued emails
Recover from temporary send failures without sending the same email twice.
When a job needs another attempt
A network timeout, rate limit, or temporary service error can interrupt a send. Your queue can try the job again after a delay. A timeout may happen after Sendery has accepted the email, so retrying needs to avoid creating a duplicate.
Reuse the same request
Save the email data and a unique idempotency key with your job before sending. Use both on every attempt. If Sendery already accepted the email, it returns the original ID instead of sending another copy.
import { Sendery } from '@sendery/sdk';
const apiKey = process.env.SENDERY_API_KEY;
if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');
const sendery = new Sendery(apiKey);
// Save this object with your job before the first attempt.
const job = {
key: 'your-idempotency-key',
input: {
to: '[email protected]',
template: 'your-template',
data: { name: 'Alex', action_url: 'https://example.com/start' },
},
};
// On each attempt, load the same saved object.
const receipt = await sendery.prepare(job.input, job.key).send();Set retry limits
Set a maximum number of attempts and a delay between them in your queue. If the API returns Retry-After, wait at least that long. Authentication, template, and billing errors need to be fixed before retrying.
After a successful request
Save the returned email ID and finish the job. Check delivery status separately. Retrying an accepted request does not send another copy; an intentional resend needs a new key.