Skip to content
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Send email from Convex with retries

Send email from a Convex app with automatic retries: queue from a mutation, back off exponentially, deduplicate with idempotency keys, and track status reactively.

To send email from a Convex app with retries, install @opencoredev/convex-email, mount it in convex/convex.config.ts, export its sender action from a "use node" file, and call email.send(ctx, message) from a mutation with an idempotencyKey. The component stores the message in the same transaction, runs your sender action after the mutation commits to send it through an Email SDK adapter such as Resend, and retries retryable failures with exponential backoff: 3 attempts by default, starting at 1 second and capped at 60 seconds between attempts.

Install and configure shows the convex/email.ts client this imports and the sender action it needs.

How retries work

Setting or case Behavior
Attempts maxAttempts on the message, then maxAttempts on the client, then the message’s retries + 1, then setConfig; 3 when none is set.
Delay retryBaseMs × 2^(attempt − 1), capped at 60 seconds. With the default 1,000 ms: 1 s, then 2 s.
Which failures retry Errors the Email SDK marks retryable: HTTP 408, 409, 425, 429 and 5xx, and connection errors such as ECONNRESET or ETIMEDOUT. A 400 or 401 fails at once.
Duplicate sends Reusing an idempotencyKey returns the existing email id while its record is kept. Each retry passes the same key to the provider, but deduplication depends on the provider: Resend keeps keys for 24 hours, and adapters without native idempotency can send twice.
Fallback adapters Used only when the first provider definitely did not send, such as a 401 or 422 rejection. A timeout, 408, 409, 429 or 5xx leaves delivery unknown, which stops fallback; the component then retries the same route if the error is retryable and attempts remain, and marks the email failed otherwise.
Stuck sends A cron runs every 5 minutes. A send stuck in processing for 10 minutes is retried if it has an idempotencyKey and attempts left, and marked failed without a key, because the provider may already have accepted it.
After the last attempt The email is failed. retry(ctx, { emailId }) starts a fresh cycle.

What the component owns

@opencoredev/convex-email is a real Convex Component: it owns isolated tables, queues provider work outside your mutation, retries safe failures, deduplicates sends, stores an event timeline, and exposes reactive delivery status.

Email SDK owns message validation and provider adapters. The Convex component owns durable application state around those sends. Convex does not allow Node code inside a component, so the provider request itself runs in a sender action your app exports with emailSender() from @opencoredev/convex-email/node.

What you get

  • Fast mutations. send stores the message and returns an email id before the provider request runs.
  • Durable idempotency. Reusing an idempotency key returns the original email id instead of queueing another message.
  • Retry and recovery. Failed attempts use exponential backoff, stale processing work is recovered safely, and terminal failures can be retried manually.
  • Provider portability. Use any serializable built-in Email SDK adapter configuration, including named fallback routes.
  • Reactive status. Query queue state, provider receipts, attempted adapters, normalized delivery state, and the complete event timeline.
  • Safe testing. Redirect all recipients to a sandbox mailbox or use the in-memory adapter without changing application flow.

Public API

Method Purpose
send(ctx, message) Queue one email and return its component id.
sendBatch(ctx, messages) Queue up to 100 messages and return ids in input order.
status(ctx, { emailId }) Read the current stored email state.
listEvents(ctx, { emailId }) Read the ordered queue, attempt, retry, and webhook timeline.
cancel(ctx, { emailId }) Cancel work that has not started.
retry(ctx, { emailId }) Start a fresh retry cycle for a terminal failure.
setConfig(ctx, config) Replace test, sender, retry, and retention defaults.

Questions

Does a Convex action retry email sends on its own?

No. Convex retries mutations on conflicts but never retries actions, and a provider request has to run in an action. The component runs your sender action from a durable queue and schedules each retry with the Convex scheduler.

Can it send through Resend and fall back to SMTP?

Yes. List both adapters on the client and set fallbackAdapters. The fallback only takes over when the first provider definitely didn’t send; see Fallbacks and retries.

How do I test without sending real email?

Use the in-memory adapter. To test real provider delivery to a mailbox you control, turn on testMode with sandboxTo, which redirects every recipient but still sends. See Test and recover.

Last updated on