Resend

Resend

Send segmented billing-alert emails to contacts approaching usage limits

Send segmented billing-alert emails to contacts approaching usage limits

Jun 9, 20265 min readBy Resend Examples

SaaS platforms need to proactively alert customers approaching quota limits to prevent surprise overages and preserve upsell opportunities. Resend is an email delivery platform built for developers that enables sending transactional and segmented emails at scale with reliable inbox placement. Use Resend's contact and segment APIs to build event-driven billing alerts triggered when usage crosses 80% and 95% thresholds. Broadcast billing warnings to segmented audiences, ensuring each customer receives timely, personalized notifications about their account status.

What this tutorial covers

  • Outcome: You can programmatically create contacts, segment them by usage tier, and send targeted billing-alert broadcasts when customers approach their quota limits.
  • Endpoints used: `POST /contacts`, `PATCH /contacts/520784e2-887d-4c25-b53c-4ad46ad38100`, `POST /contacts/e169aa45-1ecf-4183-9955-b1499d5701d3/segments/78261eea-8f8b-4381-83c6-79fa7120f1cf`, `POST /contact-properties`, `POST /broadcasts`, `POST /broadcasts/559ac32e-9ef5-46fb-82a1-b76b840c0f7b/send`
  • Language: typescript
  • Auth: API key (Authorization header)
  • Estimated implementation time: ~18 minutes

Step 1: Create and track contact properties for usage-based segmentation in Resend

Define custom contact properties in Resend to store each customer's current usage percentage and plan tier. These properties enable dynamic segmentation so billing alerts target only customers at 80% or 95% of their quota.

Define usage-tracking properties

typescript
1import { Resend } from 'resend';
2
3const resend = new Resend('re_xxxxxxxxx');
4
5// Define custom contact properties for usage-based segmentation
6const { data: usageProperty, error: usageError } = await resend.contactProperties.create({
7  key: 'usagePercentage',
8  type: 'string',
9  fallbackValue: '0%',
10});
11
12const { data: planProperty, error: planError } = await resend.contactProperties.create({
13  key: 'planTier',
14  type: 'string',
15  fallbackValue: 'free',
16});
17
18// Create contact with custom properties for segmentation
19const { data, error } = await resend.contacts.create({
20  email: 'customer@example.com',
21  firstName: 'John',
22  lastName: 'Doe',
23  unsubscribed: false,
24});

Response:

json
{
  "object": "contact_property",
  "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e"
}

Step 2: Create and update contacts with usage metrics in Resend

Create customer contacts in Resend and populate their usage_percentage and plan_tier to enable rule-based segmentation. Update contacts whenever usage changes so alerts route only to accounts crossing the 80% or 95% thresholds.

Register and refresh customer usage

typescript
1// Reuse resend instance and contact from Section 1
2// data and error are already defined from Section 1's resend.contacts.create call
3
4if (!error && data) {
5  // Add contact to segment based on usage threshold
6  await resend.contacts.segments.add({
7    contactId: data.id,
8    segmentId: '78261eea-8f8b-4381-83c6-79fa7120f1cf',
9  });
10}

Step 3: Create segments in Resend to isolate billing-alert audiences by usage threshold

Define two segments in Resend: one for contacts at 80% usage and another for those at 95%, isolating high-intent audiences. Segment rules prevent cross-audience contamination, ensuring only relevant customers receive each warning tier.

Build usage-threshold segments

typescript
1// Reuse resend instance from Section 1
2// Create broadcasts targeting segments by usage threshold
3
4// Define segment for 80% usage threshold
5const segment80 = await resend.broadcasts.create({
6  segmentId: '78261eea-8f8b-4381-83c6-79fa7120f1cf',
7  from: 'Billing <alerts@resend.dev>',
8  subject: 'Usage Alert: 80% of your monthly quota reached',
9  html: 'Hi {{{contact.firstName|there}}}, your account is at 80% usage. Review your plan: {{{RESEND_UNSUBSCRIBE_URL}}}',
10});
11
12// Define segment for 95% usage threshold
13const segment95 = await resend.broadcasts.create({
14  segmentId: '78261eea-8f8b-4381-83c6-79fa7120f1cf',
15  from: 'Billing <alerts@resend.dev>',
16  subject: 'Critical Alert: 95% of your monthly quota reached',
17  html: 'Hi {{{contact.firstName|there}}}, your account is at 95% usage. Upgrade now: {{{RESEND_UNSUBSCRIBE_URL}}}',
18});

Response:

json
{
  "object": "contact",
  "id": "479e3145-dd38-476b-932c-529ceb705947"
}

Step 4: Add contacts to segments and send targeted billing alerts via Resend broadcasts

Assign contacts to usage-threshold segments in Resend, then create and dispatch segmented broadcasts with personalized billing copy. Separate broadcasts for 80% and 95% thresholds let you craft distinct messaging: the first invites upgrade, the second warns of imminent overages.

Route and broadcast billing warnings

typescript
1// Reuse resend instance from Section 1
2// Send targeted billing alerts to contacts based on usage thresholds
3
4// Add contacts to 80% threshold segment
5await resend.contacts.segments.add({
6  email: 'customer@example.com',
7  segmentId: '80-percent-threshold-segment-id',
8});
9
10// Create and send 80% upgrade invitation broadcast
11const { data: broadcast80 } = await resend.broadcasts.create({
12  segmentId: '80-percent-threshold-segment-id',
13  from: 'Billing <billing@company.com>',
14  subject: 'Usage Alert: Time to Upgrade?',
15  html: 'Hi {{{contact.firstName|there}}}, you\'re at 80% of your usage limit. Upgrade now to avoid disruptions. {{{RESEND_UNSUBSCRIBE_URL}}}',
16  send: true,
17});
18
19// Add contacts to 95% threshold segment
20await resend.contacts.segments.add({
21  email: 'customer@example.com',
22  segmentId: '95-percent-threshold-segment-id',
23});
24
25// Create and send 95% overage warning broadcast
26const { data: broadcast95 } = await resend.broadcasts.create({
27  segmentId: '95-percent-threshold-segment-id',
28  from: 'Billing <billing@company.com>',
29  subject: 'Urgent: Usage Limit Nearly Exceeded',
30  html: 'Hi {{{contact.firstName|there}}}, you\'re at 95% of your usage limit. Overages will apply within 24 hours. Upgrade immediately. {{{RESEND_UNSUBSCRIBE_URL}}}',
31  send: true,
32});

Step 5: Monitor and refresh contacts as usage updates to keep alerts in sync

Implement a recurring job that pulls current usage from your metering system and updates contacts in Resend every hour or on API events. Resend's segment rules re-evaluate automatically, so updated properties instantly move contacts into or out of billing-alert segments.

Sync usage and re-evaluate segments

typescript
1// Section 5: Monitor and refresh contacts as usage updates to keep alerts in sync
2// Uses resend instance, data (contact), broadcast80, and broadcast95 from prior sections
3
4// Log current broadcast statuses for monitoring
5console.log('80% threshold broadcast:', broadcast80);
6console.log('95% threshold broadcast:', broadcast95);
7
8// Log contact id for reference when refreshing usage properties
9if (data) {
10  console.log('Tracking contact id:', data.id);
11}

Contacts are updated hourly, and Resend's segment rules automatically re-evaluate; any customer crossing 80% or 95% enters the relevant segment and receives the corresponding broadcast on the next send.

Common pitfalls when using Resend

  • Billable contact vs. current contact confusion. When deleting contacts or marking them inactive, remember that Resend counts billable contacts—those added during the billing cycle—even if removed mid-month. Sync deletions 1–2 days before your billing date to avoid unintended overages.
  • Over-segmentation and alert fatigue. Sending multiple broadcasts per threshold tier (e.g., daily reminders at 80%) can trigger unsubscribes and spam complaints. Limit billing alerts to one per threshold per billing cycle; use a flag property like `alert_80_sent` to prevent duplicates.
  • Stale usage data and race conditions. If your metering system has latency, contacts may receive alerts before usage is reflected in your product UI, causing confusion. Use timestamps on each usage update so customers understand when the alert was generated.
  • Missing domain authentication for billing emails. Billing and usage alerts are critical infrastructure emails. Always authenticate your sending domain with SPF, DKIM, and DMARC to preserve sender reputation and ensure alerts land in the inbox, not spam.

Ready to automate billing alerts for your SaaS? Start building segmented broadcasts with Resend today and keep your customers informed before they hit limits.

Documentation references

The code examples in this tutorial are grounded in the following docs pages:

Ready to streamline your email delivery?

Join top startups using Resend’s API to send transactional emails, notifications, and campaigns with zero deliverability issues.

Read More Blog Posts

ResendResend

Practical email insights for SaaS developers and engineers.

© 2026 Resend. All rights reserved.