Sendery
Sendery

Guides

Retry background jobs

Keep the same email request when retrying a background task.

Save the request once

Save the recipient, template, variables, locale if used, and a unique idempotency key with your job before the first send. Load the saved values on every attempt. This JavaScript example shows the data to keep.

JavaScript
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: 'welcome-123',
  input: {
    to: '[email protected]',
    template: 'welcome',
    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();

Handle a timeout

A timeout can occur after Sendery accepted the email. Retry the saved request with its original key. If it was accepted, Sendery returns the original ID. Rebuilding data from a changed user or order can cause a 409 idempotency_conflict.

Set retry limits

Set a maximum attempt count and delays in your job system. Each SDK request has a 10-second timeout. The example uses send() for one attempt per job; use retry() only if you also want retries within that attempt. Honor Retry-After for rate limiting, and fix validation or billing errors before trying again.

After acceptance

Save the message ID and check its status. Retrying an accepted request does not resend a failed delivery. An intentional new send needs a new key.