Email provider failover means your app sends through a second email provider when the first is down, rate limiting you, or has paused your account. Done well, users never notice: a login code arrives a few seconds late instead of not at all. The setup has four parts: a verified domain on both providers, clear rules for when to switch, idempotency to limit duplicates, and suppression lists kept in sync.
Why failover is worth it
Every provider has outages, and every provider can restrict an account during a review. When that happens, the emails that hurt most are the ones users are waiting for: login codes, password resets, email confirmations and receipts. A second provider costs little while idle, and on many plans an idle backup is free or close to it.
Failover is not a way around a provider’s rules. If your account was paused for high bounces, the backup will see the same bounces. Use failover for availability, and fix list problems at the source. Our guide to how providers review accounts covers that side.
Which mail should fail over
| Email type | Fail over? |
|---|---|
| Login codes, magic links, password resets | Yes |
| Email confirmations, receipts, invoices | Yes |
| Alerts and notifications | Usually |
| Newsletters and campaigns | No, wait for the primary |
Keeping campaigns off the backup also protects the backup’s reputation for the mail that matters.
DNS: two providers, one domain
Both providers need to pass SPF or DKIM in alignment with your From domain, so DMARC passes whichever one sends.
- DKIM: each provider gives you its own selector (for example
s1._domainkey,mc1._domainkey). Publish both. They do not conflict. - SPF: many providers, Mailcandor included, use a bounce subdomain such as
send.acme.comwith its own SPF record, so your root SPF record does not change. If a provider asks you to add aninclude:to your root record, watch the 10 DNS lookup limit. - DMARC: one record covers both. With DKIM aligned on both providers, it passes either way.
Verify the domain on the backup before you need it. DNS changes during an outage are slow and stressful.
When to switch, and when not to
| Primary answer | Action |
|---|---|
| Network error or timeout | Fail over |
5xx |
Fail over |
429 rate limit or quota |
Fail over, or retry after retry-after |
401 or 403 meaning the key or account stopped working |
Fail over and alert a person |
400 or 422 validation error |
Do not fail over. Fix the request |
2xx |
Done |
A 403 can also mean the From domain is not verified. Log the error type so you can tell the difference later.
Working code: two providers, one request body
The simplest failover uses two providers that accept the same request. Mailcandor accepts the Resend request body at /v1/emails, so a Resend-shaped payload can go to either host unchanged. The same idea works with SendGrid’s v3 body using the SendGrid-compatible endpoint.
const providers = [
{ name: 'resend', url: 'https://api.resend.com/emails', key: process.env.RESEND_API_KEY },
{ name: 'mailcandor', url: 'https://api.mailcandor.com/v1/emails', key: process.env.MAILCANDOR_KEY },
];
const FAILOVER = (status) => status >= 500 || status === 429 || status === 401 || status === 403;
let primaryDownUntil = 0; // simple circuit breaker
export async function sendCritical(email, idempotencyKey) {
const order = Date.now() < primaryDownUntil ? providers.slice(1) : providers;
let lastError;
for (const p of order) {
let res;
try {
res = await fetch(p.url, {
method: 'POST',
headers: {
Authorization: `Bearer ${p.key}`,
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
},
body: JSON.stringify(email),
signal: AbortSignal.timeout(10_000),
});
} catch (err) {
res = null; // network error or timeout
lastError = err;
}
if (res?.ok) return { provider: p.name, ...(await res.json()) };
if (res) {
lastError = new Error(`${p.name} ${res.status}: ${await res.text()}`);
if (!FAILOVER(res.status)) throw lastError; // a bad request fails everywhere
}
if (p === providers[0]) primaryDownUntil = Date.now() + 5 * 60_000;
}
throw lastError;
}
await sendCritical(
{
from: 'Acme <hello@acme.com>',
to: 'sam@example.com',
subject: 'Your login code',
html: '<p>Your code is <b>481 203</b></p>',
},
'login-code-user-8812-attempt-1',
);
After a failure, the breaker sends straight to the backup for five minutes instead of waiting on a timeout for every email. In production, keep the breaker state in Redis or your database so every instance shares it, and send an alert when it trips.
Duplicates and idempotency
The awkward case is a timeout where the primary actually accepted the email. The backup then sends a second copy. You cannot fully prevent this across two providers, because each provider’s idempotency key only protects against retries on that provider. You can make it rare:
- Use a timeout long enough for a normal response (10 seconds is reasonable for a send).
- Use a stable idempotency key per email, so a retry on the same provider never duplicates.
- Accept that a rare duplicate login code is far better than a missing one.
Keep suppression lists in sync
If an address hard-bounces or complains on one provider, the other must not mail it. Otherwise failover sends straight to addresses that hurt your reputation. Subscribe to bounce and complaint webhooks from both providers and copy each address to the other. With Mailcandor:
curl https://api.mailcandor.com/v1/suppressions \
-H "Authorization: Bearer $MAILCANDOR_KEY" \
-H "Content-Type: application/json" \
-d '{ "emails": ["gone@example.com"], "reason": "Hard bounce on primary provider" }'
See the suppression list help page for how Mailcandor uses the list.
Webhooks from two providers
Events arrive from both providers in different shapes. Normalize them in one handler: map each provider’s event to your own delivered, bounced and complained, keyed by the provider’s email id, which you stored along with which provider sent it.
Test it before you need it
- Point the primary URL at a closed port in staging and check the backup sends.
- Send through the backup on a schedule (a daily test to yourself) so you notice expired keys or DNS drift.
- Alert when the circuit breaker trips, so a person knows you are running on the backup.
Where Mailcandor fits
Mailcandor works as either side of the pair. Its send endpoint takes the Resend body, SendGrid’s POST /v3/mail/send and Postmark’s POST /email, so a backup is a second URL rather than a second integration. Unlimited domains on every plan mean the backup can cover every brand you send for, and the Starter plan is free for up to 3,000 emails a month for a quiet standby. Access is by request through the pricing page.