Payment failure and dunning email templates: production-ready HTML, React Email, and webhook implementation guide
Payment failure and dunning email templates with production ready HTML, React Email, and webhook implementation for SaaS developers. Build your dunning system as a state machine with idempotent webhook handlers, decline code segmentation, and per stage recovery metrics.
On this page
TLDR: Build your dunning system as a state machine, not a collection of email templates. Segment soft declines from hard declines before writing a single template, use the event_id from your payment webhook as your idempotency key to prevent duplicate sends, and track recovery rate per email stage rather than overall churn. This guide provides production-ready HTML templates, React Email components, and webhook implementation patterns for a system that prevents silent churn by recovering failed payments through timed, segmented email sequences. send.io handles the email delivery layer with template versioning, event webhooks, and a shared suppression list while you own the retry logic.A payment gateway retries a webhook. Your dunning system sends duplicate emails. The customer churns. The bug was not in the email copy. It was in the deduplication logic.
Most dunning guides start with tone and timing. This guide starts with the state machine and the webhook contract, because a well-written dunning email sent twice is worse than a mediocre email sent once. This is for backend engineers and platform teams building custom dunning systems. If you use an off-the-shelf billing platform with native dunning (Chargebee, Recurly) or rely on Stripe Billing's built-in dunning without custom email templates or cross-provider contact management, this is not for you.
Soft vs. hard payment decline: segmentation that drives recovery
You need different email content, cadence, and retry logic for soft declines and hard declines. A soft decline means the charge can succeed later. A hard decline means it cannot. Sending a retry email to a card that will never succeed wastes a touchpoint and damages sender reputation when the customer marks you as spam.
Managing retriable billing errors
Your payment gateway returns a soft decline when the card is valid but the charge fails for a temporary reason. Common soft decline codes include insufficient_funds, card_velocity_exceeded, processing_error, and issuer_not_available. Because the failure is temporary, a scheduled retry can recover the payment without any customer action.
Handling irrecoverable charge errors
A hard decline tells you the card cannot be charged again. Examples include expired_card, fraudulent, lost_card, and stolen_card. Only a new payment method fixes the problem, so route these failures to a payment method update request instead of a retry.
Automating dunning triggers by decline code
Map each decline code to a dunning path before you write any templates:
Decline code | Category | Recommended action | Suggested email template |
|---|---|---|---|
insufficient_funds | Soft | Retry in 3-5 days | First failure notice (retry scheduled), a template name used in this guide, not a payment processor standard |
card_velocity_exceeded | Soft | Retry in 24 hours | First failure notice (retry scheduled) |
processing_error | Soft | Retry immediately, then at 1 hour and 4 hours | First failure notice (retry scheduled) |
expired_card | Hard | Request new card | Payment method update request, a template name used in this guide, not a payment processor standard |
fraudulent | Hard | Do not retry | Payment method update request |
lost_card | Hard | Do not retry | Payment method update request |
Store this mapping in your application config, not in the email template. When a webhook arrives, check the decline code, choose the path, then render the appropriate template.
Essential dunning email templates for SaaS
Build your production dunning system with five core templates: first failure, retry reminder, final notice, suspension, and reactivation. According to Baremetrics, most subscription businesses send five to six dunning emails spread over a 30-day window, rather than clustering them in the first few days. The sequence below assumes a 14-day active dunning window followed by suspension and a reactivation attempt.
Triggering the first dunning event
Fire the first email on Day 0, immediately after the payment fails. For a soft decline, it tells the customer you will retry automatically in a specified number of days. For a hard decline, it asks them to update their payment method now.
According to Baremetrics, the first email is the highest-converting message in a dunning sequence, because the issue is fresh and the customer's card is often still nearby. Send it within 24 hours of the failure. Baremetrics attributes the first email's performance to recency. No source here quantifies same-day versus next-day sends, so measure that delta against your own baseline. Track open, click, and recovery rates for this email so you have a baseline for later steps.
Configuring dunning retry intervals
The second and third emails fire on Day 3 and Day 7 for a 14-day dunning cycle. Each reminds the customer that a retry is scheduled or has occurred, and each includes the same payment update link. For soft declines, the retry email acknowledges that a retry happened and asks the customer to update their card if the retry failed. For hard declines, every email in the sequence asks for a new payment method because no retry will succeed.
Handling post-dunning account closure
After the final retry fails, the account moves to a suspended state. The suspension email states what happened, what the customer lost access to, and how long they have before data deletion. The suspension email is transactional, not marketing. It must be deliverable even if the customer previously unsubscribed from promotional email. send.io keeps one contact record across transactional and broadcast sends, so you can remove unsubscribed customers from broadcasts, while transactional payment notices send through the same contact record rather than a second integration. Send a grace period reminder that states the specific suspension date, so the customer has a final chance to update their payment method. The reminder day varies by implementation, so schedule it relative to your own suspension date rather than a fixed day.
Automating final suspension emails
The suspension email fires when the dunning cycle ends without recovery. It confirms the account is suspended, states the reactivation deadline, and provides a direct link to update the payment method and restore access. Include a specific date for data deletion if your retention policy includes one. State the policy without threatening language.
Optimizing dunning reactivation emails
The reactivation email fires after the suspension takes effect, offering the customer a final opportunity to restore access before data deletion. This email has the lowest recovery rate in the sequence, but it costs nothing to send and occasionally recovers a customer who missed earlier notices. Track the reactivation rate separately so you can measure whether incentives affect recovery without distorting earlier-stage metrics.
Payment failed email template for developers
A payment failed email template for developers must be runnable, customizable, and idempotent. The templates below use production-ready HTML with inline CSS for email client compatibility and React Email components for teams that prefer component-based templating. send.io supports both approaches through its email templates and versioning system, which allows you to create, render, test, and publish reusable templates in a visual editor or through the API.
Standardized HTML templates for dunning
The HTML template below uses table-based layout and inline styles for maximum email client compatibility:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: #f4f4f4;">
<table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f4;">
<tr>
<td align="center" style="padding: 40px 0;">
<table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 8px;">
<tr>
<td style="padding: 40px;">
<h1 style="margin: 0 0 20px; font-size: 24px; color: #333333;">Payment failed for your subscription</h1>
<p style="margin: 0 0 15px; font-size: 16px; line-height: 1.5; color: #666666;">
Hi {{customer_name}},
</p>
<p style="margin: 0 0 15px; font-size: 16px; line-height: 1.5; color: #666666;">
Your payment of {{amount}} for your subscription could not be processed. The charge will be retried automatically on {{retry_date}}.
</p>
<p style="margin: 0 0 15px; font-size: 16px; line-height: 1.5; color: #666666;">
Card ending in {{card_last4}}
</p>
<p style="margin: 0 0 25px; font-size: 16px; line-height: 1.5; color: #666666;">
If you'd like to update your payment method now, you can do so below.
</p>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="background-color: #007bff; border-radius: 4px;">
<a href="{{update_payment_url}}" style="display: inline-block; padding: 12px 30px; color: #ffffff; text-decoration: none; font-size: 16px;">Update payment method</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
For Stripe, {{amount}} maps to data.object.amount\_due formatted as currency, and {{card\_last4}} maps to data.object.default\_payment\_method.card.last4. The invoice.payment\_failed invoice payload references the customer by ID and does not include a customer\_name field, so {{customer\_name}} needs an expand step (expand customer on the invoice, then read customer.name) or a lookup against your own customer records. The same caveat applies to customer\_email. Likewise, default\_payment\_method is returned as an ID unless you expand it.
Standardized dunning email components
For teams using React Email, install with npm i react-email@latest and define email templates with React components:
import { Html, Head, Body, Container, Section, Text, Button, Heading } from 'react-email';
export default function PaymentFailedEmail({ customerName, amount, retryDate, cardLast4, updateUrl }) {
return (
<Html>
<Head />
<Body style={{ backgroundColor: '#f4f4f4', fontFamily: 'Arial, sans-serif' }}>
<Container style={{ backgroundColor: '#ffffff', margin: '40px auto', padding: '40px', borderRadius: '8px', maxWidth: '600px' }}>
<Heading style={{ fontSize: '24px', color: '#333333', marginBottom: '20px' }}>
Payment failed for your subscription
</Heading>
<Text style={{ fontSize: '16px', lineHeight: '1.5', color: '#666666', marginBottom: '15px' }}>
Hi {customerName},
</Text>
<Text style={{ fontSize: '16px', lineHeight: '1.5', color: '#666666', marginBottom: '15px' }}>
Your payment of {amount} for your subscription could not be processed. The charge will be retried automatically on {retryDate}.
</Text>
<Text style={{ fontSize: '16px', lineHeight: '1.5', color: '#666666', marginBottom: '15px' }}>
Card ending in {cardLast4}
</Text>
<Text style={{ fontSize: '16px', lineHeight: '1.5', color: '#666666', marginBottom: '25px' }}>
If you'd like to update your payment method now, you can do so below.
</Text>
<Button href={updateUrl} style={{ backgroundColor: '#007bff', color: '#ffffff', padding: '12px 30px', borderRadius: '4px', textDecoration: 'none', fontSize: '16px' }}>
Update payment method
</Button>
</Container>
</Body>
</Html>
);
}
Defining data schema for dunning emails
Define the dunning email data schema as a TypeScript interface so template rendering is type-safe:
interface DunningEmailData {
customer_name: string;
customer_email: string;
amount: string; // e.g., "$49.00"
currency: string; // e.g., "USD"
card_last4: string;
decline_code: string; // e.g., "insufficient_funds"
decline_category: 'soft' | 'hard';
retry_date?: string; // ISO 8601 date, only for soft declines
update_payment_url: string;
suspension_date?: string; // Only in final notice and suspension emails
event_id: string; // Webhook event ID for idempotency - prevents duplicate sends on retry
}
The event_id field is critical for idempotency. Store it in your database alongside the email send record so you can deduplicate retries. The decline_category field determines which template variant to render.
Adaptive design patterns for dunning
Dunning emails must render correctly on mobile devices and in email clients with limited CSS support. Use table-based layouts, inline styles, and a single-column design. Include a plain-text version of every dunning email because some enterprise email clients block HTML email by default.
Configuring idempotent retry for payment events
Idempotency prevents duplicate dunning emails when a payment gateway retries a webhook. Without idempotency, a customer receives the same email multiple times, which damages trust and increases spam complaints. The idempotency key is the event_id from the payment webhook, not the customer ID.
Structuring the 0-14 day email cadence
A 14-day active dunning window with emails on Day 0, Day 3, Day 7, and Day 14 balances recovery rate with customer experience. For soft declines, schedule the first retry for Day 3 and the second retry for Day 7. For hard declines, skip the retry schedule and send the first email immediately, the second email on Day 3, and the final notice on Day 7.
Managing dunning cycle retry cadence
Payment gateways impose retry limits. Stripe recommends a maximum of 8. Your dunning state machine must track the attempt_count from the payment webhook and stop retrying after a defined limit. The attempt_countattribute on the invoice.payment_failed webhook indicates how many attempts have been made so far.
Reliable webhook implementation for dunning emails
Your payment gateway fires a webhook when a payment fails. Your application receives the webhook, checks idempotency, updates the dunning state machine, and triggers the appropriate email. send.io handles the email delivery layer through its API, accepts a client-generated Idempotency-Key header, and stores it for 24 hours, returning the original result on retry instead of sending a duplicate.
The webhook handler must be fast, idempotent, and fault-tolerant. If the handler times out, the gateway will retry. If the handler processes the same event twice, the customer receives duplicate emails.
[VISUAL: Webhook-to-email trigger architecture diagram showing payment gateway webhook, send.io event webhook endpoint, state machine check, template render, email send, and webhook confirmation with arrows indicating data flow]
Key webhook triggers for dunning
Stripe fires invoice.payment_failed when a payment for an invoice fails. The webhook payload includes the invoice object, the payment intent, and the attempt_count attribute.
Paddle fires transaction.payment_failed when a payment fails for a transaction.
Preventing duplicate dunning emails
Payment gateways use at-least-once delivery, which means a webhook can be delivered multiple times. Pair at-least-once delivery with idempotent effects and you get duplicate-safe processing.
Use the event_id from the webhook payload as your idempotency key. According to Digital Applied's webhook reference, every well-designed webhook carries a unique event ID that stays constant across retries. Do not synthesize an idempotency key by hashing the request body, because two legitimately distinct events can share a body.
Without idempotency (duplicate sends possible):
app.post('/webhooks/payment-failed', async (req, res) => {
const event = req.body;
const customer = await getCustomer(event.data.object.customer);
await sendDunningEmail(customer, event.data.object);
res.status(200).send('OK');
});
With idempotency (single send guaranteed):
app.post('/webhooks/payment-failed', async (req, res) => {
const event = req.body;
const eventId = event.id;
const existingEvent = await db.webhookEvents.findOne({ eventId });
if (existingEvent) {
return res.status(200).send('Already processed');
}
await db.webhookEvents.insert({ eventId, processedAt: new Date() });
const customer = await getCustomer(event.data.object.customer);
await sendDunningEmail(customer, event.data.object, {
headers: { 'Idempotency-Key': eventId }
});
res.status(200).send('OK');
});
The second version checks the database for the event_id before sending the email. When calling send.io's API, pass the same event_id as the Idempotency-Key header so send.io's 24-hour deduplication window provides a second layer of protection.
Implementing a webhook dead-letter queue
A dead-letter queue stores webhook events that fail processing after multiple retries. This dead-letter queue is for payment webhook processing failures on your application side, not for email delivery failures. send.io handles email delivery retries and provides webhook events for bounce and complaint notifications. Store the raw webhook payload, the error message, and the timestamp in the dead-letter queue. Alert on dead-letter queue depth so a growing queue triggers an on-call page.
Production guardrails for email compliance
Dunning emails are transactional, so they must be deliverable even if the customer unsubscribed from marketing email. Authenticate your sending domain and meet regional legal requirements, or the emails land in spam or violate regulations.
Configuring SPF, DKIM, and DMARC records
SPF (defined in RFC 7208) is an email authentication protocol that allows domain owners to publish a DNS TXT record listing which IP addresses are authorized to send email. DKIM (defined in RFC 6376) is a cryptographic email authentication protocol that enables a sending domain to digitally sign outgoing messages so receiving mail servers can verify the message was not altered in transit.
In May 2026 the IETF published RFC 9989, the updated DMARC standard sometimes called DMARCbis, which replaces the original 2015 specification. send.io guides SPF, DKIM, and DMARC verification when you add a sending domain through the dashboard. You still publish the DNS records at your DNS provider.
Managing email unsubscribe webhooks
CAN-SPAM requires honoring opt-out requests within ten business days, but Gmail and Yahoo enforce a 2-day window, according to Tomba's compliance table, and GDPR requires immediate action. Build for the strictest standard: 2 days. send.io's suppression list API allows you to add and remove email addresses programmatically so you can remove unsubscribed customers from broadcasts, while transactional payment notices send through the same contact record rather than a second integration.
Automating suppression list synchronization
send.io automatically suppresses bounce and spam-complaint addresses. The suppression list is shared across transactional and broadcast sends, so a hard bounce on a dunning email prevents a marketing campaign from sending to the same invalid address. Sync your application database with send.io's suppression list daily and flag customers with invalid email addresses for manual review.
Regional legal email requirements
CAN-SPAM applies to commercial email sent to US recipients, GDPR applies to any email sent to EU or UK residents, and CASL applies to commercial email sent to Canadian recipients. Include your company's physical address in every dunning email because CAN-SPAM requires a valid physical postal address in all commercial email.
KPIs for tracking failed payment resolution
A dunning system is measurable at every stage. Track recovery rate per email, payment method update rate, and churn rate by decline code so you know which template or cadence change actually moved revenue recovery.
According to Slicker's 2025 failed payment benchmarks, as quoted by Baremetrics, the industry median recovery rate is 47.6%, but top-performing subscription businesses reach recovery rates of 70-85% by layering multiple tactics, including smart retry logic and sequenced emails.
Tracking dunning email performance
Track open rate, click rate, and recovery rate for each email in the dunning sequence. Recovery rate per email is the percentage of customers who complete a successful charge within an attribution window you define after receiving that specific email, whether through automatic retry or manual payment method update. No industry standard fixes that window, and published sources use different ones depending on the recovery context, so choose a window that fits your retry cadence and document it. Use the same window across every stage so per-step comparisons stay consistent.
Tracking payment method update rates
The payment method update rate is the percentage of customers who click the update link and successfully add a new payment method. A low update rate with a high open rate suggests the email content is not compelling or the update flow has too much friction. A high update rate with a low recovery rate suggests customers are updating their payment method but the new card is also failing.
Recovery metrics per dunning step
Recovery per step shows which email in the sequence drives the most revenue. For example, if the first email recovers 13% of failed payments and the final notice recovers 2%, the first email drives six times more revenue. This tells you to optimize the first email's timing and deliverability before refining later-stage copy.
Mapping churn to payment failure codes
Track which decline codes lead to the highest churn. Hard declines have a higher churn rate than soft declines because they require customer action to resolve. Within hard declines, expired_card has a lower churn rate than fraudulent because an expired card is an innocent mistake while a fraudulent flag indicates a deeper problem.
Test the event webhook and template versioning flow in the send.io sandbox before wiring your payment gateway to production. Provision a test domain, configure a webhook endpoint, and send test events through the API to verify idempotency, template rendering, and suppression list behavior before your first real payment fails.
FAQs
What is the difference between a soft decline and a hard decline?
A soft decline means the payment can succeed on retry because the card is valid but the charge failed for a temporary reason such as insufficient funds or a processing error. A hard decline means the card cannot be charged again because it is expired, lost, stolen, or flagged as fraudulent, and only a new payment method will fix it.
How many dunning emails should a SaaS send?
Most subscription businesses send five to six dunning emails spread over a 30-day window. The first email fires on Day 0 immediately after the payment fails, followed by reminders on Day 3, Day 7, and Day 14, then a suspension notice and a final reactivation attempt.
How can you prevent duplicate dunning emails when a payment webhook fires twice?
Use the event_id from the payment webhook payload as your idempotency key. Store it in your database before sending the email, check if it already exists on every webhook delivery, and pass the same event_id as the Idempotency-Key header when calling send.io's API for a second deduplication layer.
What decline codes should trigger an immediate payment method update request instead of a retry?
Hard decline codes such as expired_card, fraudulent, lost_card, and stolen_card should trigger an immediate payment method update request because retrying the same card will never succeed.
What is the recovery rate for a well-timed dunning email sequence?
A well-timed dunning sequence sits between the industry median recovery rate of 47.6% and the 70-85% range reached by top-performing subscription businesses. Slicker's 2025 failed payment benchmarks, as quoted by Baremetrics, report the median, and top performers reach the higher range by layering smart retry logic with sequenced emails. Your own rate depends on your decline-code mix, so measure it per email stage against the baseline you define.
Key terms glossary
Soft decline: A payment failure where the card is valid but the charge failed for a temporary reason such as insufficient funds or a processing error. The charge can succeed on retry.
Hard decline: A payment failure where the card cannot be charged again because it is expired, lost, stolen, or fraudulent. Only a new payment method will resolve it.
Idempotency key: A unique identifier for a webhook event or API request that prevents duplicate processing. The same key submitted multiple times produces the same result without side effects.
Dead-letter queue: A storage system for webhook events that fail processing after multiple retries. Events in the dead-letter queue are reviewed manually or reprocessed after the underlying issue is resolved.
Suppression list: A database of email addresses that should not receive email due to hard bounces, spam complaints, or unsubscribe requests. send.io shares one suppression list across transactional and broadcast sends, so a hard bounce on a dunning email also stops marketing campaigns from sending to that address.
Dunning cadence: The schedule of emails and retry attempts that occur after a payment failure. A typical active dunning window spans 14 days with four to five emails, followed by a suspension period and optional reactivation attempt.
Recovery rate: The percentage of failed payments that result in a successful charge after dunning. Measured per email stage and across the entire sequence.