Introduction to Resend .NET
Relevant source files
The following files were used as context for generating this wiki page:Resend .NET is a comprehensive library for interacting with the Resend API using C#. It allows developers to send emails, manage domains, handle contacts, and configure webhooks within .NET applications.
The library targets .NET 8 and .NET 10, providing a modern, asynchronous interface for all Resend service features. It includes support for dependency injection and integrates with popular .NET ecosystem tools like FluentEmail and Razor for template rendering.
Sources: README.md:1-12, src/Resend/README.md:1-10, src/Resend/README.md:38-40
Core Architecture and Components
The library's architecture centers on the IResend interface and its primary implementation, ResendClient. The client uses HttpClient to communicate with Resend's REST API.
IResend Interface
IResend defines the contract for all operations supported by the SDK. It organizes functionality into logical regions:
- Email: Operations for sending, retrieving, and batching emails.
- Domains: Tools for adding, verifying, and deleting sender domains.
- Contacts & Audiences: Management of recipient lists and individual contact details.
- Templates & Automations: Creation and execution of automated workflows and reusable email designs.
- Webhooks: Configuration of real-time event notifications.
Sources: src/Resend/IResend.cs:4-11, src/Resend/IResend.cs:13-100, src/Resend/IResend.cs:150-160
ResendClient Implementation
ResendClient handles the low-level HTTP logic, including:
- Authentication: It applies a Bearer token to every request.
- Identification: It attaches User-Agent headers (e.g.,
resend-sdk,dotnet) to identify the client version. - Execution Flow: It uses internal
Executemethods to serialize payloads to JSON and deserialize API responses into strongly-typed .NET objects. - Error Handling: It converts API error responses into
ResendExceptionobjects when configured to do so.
Sources: src/Resend/ResendClient.cs:17-45, src/Resend/ResendClient.cs:522-580
Request Flow Diagram
The following diagram illustrates how a request travels from user code through the SDK to the Resend API.
Features and Supported Objects
The SDK covers the full breadth of the Resend API. The table below summarizes the primary objects managed by the client.
| Object | Primary Operations | Source |
|---|---|---|
| Send, Batch, Retrieve, Reschedule, Cancel | src/Resend/README.md:15 | |
| Domain | List, Add, Retrieve, Update, Verify, Delete | src/Resend/README.md:17 |
| API Key | List, Create, Delete, Update | src/Resend/README.md:18 |
| Contact | Add, Retrieve, Update, Delete, List Segments | src/Resend/ResendClient.Contacts.cs:8-150 |
| Broadcast | List, Add, Retrieve, Update, Send, Schedule | src/Resend/README.md:19 |
| Templates | List, Create, Publish, Duplicate | src/Resend/README.md:23 |
| Webhooks | Create, Update, Rotate Secret, Event Replay | src/Resend/README.md:24 |
Setup and Integration
Dependency Injection
In typical applications, you configure the SDK during startup. The AddResend extension method registers the necessary services in the DI container.
using Resend;
builder.Services.AddResend( o =>
{
o.ApiToken = Environment.GetEnvironmentVariable( "RESEND_APITOKEN" )!;
} );
Sources: README.md:52-60, src/Resend/README.md:43-50
Integration with Ecosystem
Resend .NET is designed to work with various rendering engines and background job processors:
- Rendering: Supports Razor and Liquid (Fluid) for generating dynamic HTML bodies.
- Async Processing: Compatible with Hangfire and Temporal for durable, retriable email sending.
- FluentEmail: A dedicated package
Resend.FluentEmailallows using Resend as a sender within the FluentEmail framework.
Sources: examples/README.md:7-15, examples/README.md:47-60, src/Resend.FluentEmail/README.md:40-55
Error Handling and Rate Limiting
The ResendClient extracts rate limit information from the HTTP headers of every response. This data is exposed via the ResendResponse object, allowing applications to monitor their quota usage.
Rate Limit Data Structure
The client parses the following headers:
ratelimit-policyratelimit-limitratelimit-remainingratelimit-resetretry-after
Sources: src/Resend/ResendClient.cs:643-653
Sequence of an Authenticated Request
The sequence below shows how the client handles authentication and communication.
Summary
Resend .NET provides a robust, type-safe wrapper around the Resend API. By utilizing .NET's asynchronous patterns and dependency injection, it facilitates the integration of advanced email features into modern software architectures.
Sources: src/Resend/README.md:1-12, README.md:1-12