Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
The Resend .NET SDK provides a set of libraries to interact with the Resend email API using C#. It targets .NET 8 and .NET 10, with .NET 9 applications utilizing the .NET 8 build. This guide explains how to install the library, configure authentication, and send your first email.
The SDK is divided into specialized packages. The core Resend package handles standard API operations like sending emails, managing domains, and handling contacts. Additional packages like Resend.Webhooks and Resend.FluentEmail provide specialized integrations for receiving webhook events or using the FluentEmail framework.
Sources: README.md:1-12, src/Resend/README.md:1-10, src/Resend.Webhooks/README.md:1-25
Installation
You must add the SDK to your project using a package manager. The packages are available on NuGet.
| Package Name | Command-line Installation | Description |
|---|---|---|
Resend | dotnet add package Resend | Core client for the Resend API. |
Resend.Webhooks | dotnet add package Resend.Webhooks | Library to receive and process Resend webhooks. |
Resend.FluentEmail | dotnet add package Resend.FluentEmail | Integration for the FluentEmail library. |
Sources: README.md:15-22, src/Resend/README.md:27-37, src/Resend.Webhooks/README.md:11-23
Initialization and Configuration
The SDK uses Dependency Injection (DI) to manage the lifecycle of the IResend client. You must obtain an API key from the Resend Dashboard before configuration.
Dependency Injection Setup
In the startup code of your application (typically Program.cs), use the AddResend extension method to register the service. You provide the API token through the configuration options.
using Resend;
builder.Services.AddResend( o =>
{
o.ApiToken = Environment.GetEnvironmentVariable( "RESEND_APITOKEN" )!;
} );
Sources: README.md:42-51, src/Resend/README.md:43-52
High-Level Component Interaction
The following diagram illustrates the flow from service registration to sending an email request via the SDK.
The IResend interface acts as the primary entry point for all API operations, abstracting the underlying HTTP communication performed by ResendClient.
Sources: src/Resend/README.md:45-75, src/Resend/IResend.cs:4-10
Basic Usage
After injecting IResend, you can perform various operations. The most common task is sending an email using the EmailSendAsync method.
Sending Your First Email
To send an email, create an instance of EmailMessage, populate the sender, recipient, subject, and body properties, and then pass it to the client.
using Resend;
public class EmailService
{
private readonly IResend _resend;
public EmailService( IResend resend )
{
_resend = resend;
}
public async Task SendWelcomeEmail()
{
var message = new EmailMessage();
message.From = "onboarding@resend.dev";
message.To.Add( "user@example.com" );
message.Subject = "Welcome to our platform";
message.HtmlBody = "<strong>It works!</strong>";
await _resend.EmailSendAsync( message );
}
}
Sources: README.md:58-75, src/Resend/README.md:55-75
Core Operations Overview
The IResend interface supports a wide variety of features beyond simple email sending.
| Category | Key Methods | Description |
|---|---|---|
EmailSendAsync, EmailBatchAsync | Sends single or multiple emails. | |
| Domains | DomainAddAsync, DomainVerifyAsync | Manages and verifies sending domains. |
| Contacts | ContactAddAsync, ContactListAsync | Manages audience contacts. |
| Templates | TemplateCreateAsync, TemplatePublishAsync | Manages reusable email templates. |
| Suppressions | SuppressionAddAsync, SuppressionListAsync | Manages the email suppression list. |
Sources: src/Resend/README.md:13-24, src/Resend/IResend.cs:12-1000
Reliability and Rendering
For production environments, the project suggests strategies for handling transient failures and complex HTML rendering.
Asynchronous and Durable Execution
API calls can fail due to network interruptions or rate limiting. The SDK is compatible with libraries that support durable activity execution and retries.
- Hangfire: Processes background jobs with persistent queues.
- Temporal: Manages state for long-running, fault-tolerant workflows.
- Quartz.NET: Schedules tasks and handles job retries.
Sources: examples/README.md:27-52
Template Engines
The SDK supports several rendering engines to avoid manual HTML string concatenation in C#.
- Razor: Syntax-efficient engine native to ASP.NET.
- Fluid: A .NET implementation of the Liquid template language.
- Handlebars.Net: Compiles Handlebars templates directly to IL bytecode.
Sources: examples/README.md:65-103
The Resend .NET SDK simplifies integration with the Resend API by providing a strongly-typed, DI-friendly client. By following these steps, you can establish a reliable email delivery system within your .NET applications.