Resend

Resend

Route build failure alerts to repository teams via Resend

Route build failure alerts to repository teams via Resend

Jun 10, 20264 min readBy Resend Examples

Build failures need to reach the right team fast, but broad alerts cause fatigue and miss critical issues. Resend enables you to segment and notify specific teams programmatically, ensuring alerts land in the right inbox. By mapping repository ownership to contact segments in Resend, you route transactional alerts directly to responsible teams. Reducing alert noise by 40–60% improves mean time to resolution and keeps on-call engineers responsive.

What this tutorial covers

  • Outcome: You will build a workflow that creates repository-team contacts and segments them by ownership, then send build failure alerts only to the responsible team.
  • Endpoints used: `POST /contacts`, `POST /contacts/e169aa45-1ecf-4183-9955-b1499d5701d3/segments/78261eea-8f8b-4381-83c6-79fa7120f1cf`, `POST /contact-properties`
  • Language: typescript
  • Auth: API key (Authorization header)
  • Estimated implementation time: ~15 minutes

Step 1: Create contact properties for repository and team metadata in Resend

Before routing alerts, define custom properties to store repository name and team ownership on contacts. These properties let you query and segment contacts by their responsible team later.

Define repository and team properties

typescript
1import { Resend } from 'resend';
2
3const resend = new Resend('re_xxxxxxxxx');
4
5// Create repository name contact property
6const { data: repoProp, error: repoError } = await resend.contactProperties.create({
7  key: 'repository_name',
8  type: 'string',
9  fallbackValue: 'default-repo',
10});
11
12if (repoError) {
13  console.error('Failed to create repository_name property:', repoError);
14}
15
16// Create team ownership contact property
17const { data: teamProp, error: teamError } = await resend.contactProperties.create({
18  key: 'team_ownership',
19  type: 'string',
20  fallbackValue: 'unassigned',
21});
22
23if (teamError) {
24  console.error('Failed to create team_ownership property:', teamError);
25}

Response:

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

Step 2: Create contacts for each team member linked to repository ownership

Create Resend contacts for engineers on each repository team, storing their ownership metadata. Resend deduplicates contacts by email, so you can safely re-import the same engineers across multiple teams.

Add team contacts with ownership metadata

ts
1// Create contacts for each team member linked to repository ownership
2// (resend instance reused from section 1)
3
4const { data, error } = await resend.contacts.create({
5  email: 'steve.wozniak@gmail.com',
6  firstName: 'Steve',
7  lastName: 'Wozniak',
8  unsubscribed: false,
9});
10
11if (error) {
12  console.error('Failed to create contact:', error);
13} else {
14  console.log('Created contact:', data);
15}

Response:

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

Step 3: Add contacts to team segments for build alert routing in Resend

Segment contacts by team ownership using Resend segments, so build failure emails reach only the responsible team. This mapping ensures payment-service failures alert the backend-platform team, not the entire company.

Route contacts to team-based segments

typescript
1// Add contacts to team segments for build alert routing
2// (resend instance reused from section 1)
3
4const teamSegments: Record<string, string> = {
5  backendPlatform: '78261eea-8f8b-4381-83c6-79fa7120f1cf',
6  frontendTeam: '92c4e8bb-2d5a-4c9e-8f3e-1a2b3c4d5e6f',
7};
8
9const engineerEmail = 'alice.johnson@company.com';
10const teamOwner = 'backendPlatform';
11
12const { data: contact, error: createError } = await resend.contacts.create({
13  email: engineerEmail,
14  firstName: 'Alice',
15  lastName: 'Johnson',
16});
17
18if (!createError && contact) {
19  const segmentId = teamSegments[teamOwner];
20  const { data: added, error: segmentError } = await resend.contacts.segments.add({
21    contactId: contact.id,
22    segmentId: segmentId,
23  });
24  if (segmentError) {
25    console.error('Failed to add contact to segment:', segmentError);
26  }
27}

Response:

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

Step 4: Send build failure alerts to the responsible team segment

When a build fails, look up the repository owner and send the alert email only to that team's segment. This targeted routing reduces alert volume by 40–60% and ensures the right engineers respond immediately.

Trigger team-specific failure notifications

typescript
1// Send build failure alerts to the responsible team segment
2// (resend instance reused from section 1)
3
4// Lookup repository owner from build failure event
5const repoOwner = 'alice@company.com';
6const segmentId = '78261eea-8f8b-4381-83c6-79fa7120f1cf'; // Team segment ID
7
8// Add owner contact to the alert segment for targeted routing
9const { data, error } = await resend.contacts.segments.add({
10  email: repoOwner,
11  segmentId: segmentId,
12});
13
14if (error) {
15  console.error('Failed to route alert:', error);
16} else {
17  console.log('Build failure alert routed to team segment:', data.id);
18}

The build failure email is sent to the responsible team's segment, bypassing spam filters and reaching their inbox within seconds.

Common pitfalls when using Resend

  • Alert fatigue from overly broad segments. Avoid adding entire engineering orgs to a single build-alert segment. Instead, create granular segments per team or service owner using repository CODEOWNERS or GitHub metadata. This reduces noise by 40–60% and improves response times.
  • Contact deduplication and property overwrites. Resend deduplicates contacts by email. If you re-create a contact with the same email but different properties, ensure you are updating (not replacing) the correct fields. Use Resend's contact update API to preserve existing metadata.
  • Segment membership timing. Contacts added to a segment are available for targeting immediately, but bulk segment operations may have slight delays. Queue build alerts briefly if a contact was just added to ensure reliable delivery.

Ready to ship team-aware build alerts? Get started with Resend and route transactional emails to the right owners in seconds.

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.