Configuration Options
Relevant source files
The following files were used as context for generating this wiki page:
Configuration Options define the parameters required to initialize and operate the Resend .NET SDK. These options manage authentication tokens and API endpoint addresses to enable communication between the .NET application and the Resend API service.
The library uses the standard .NET Dependency Injection (DI) pattern to apply these settings. This ensures that the IResend client is correctly instantiated with the necessary credentials and endpoint metadata before it executes any API calls. Sources: README.md:46-56, src/Resend/README.md:38-46
Core Client Options
The ResendClientOptions class acts as the central data structure for SDK settings. It stores the sensitive API token and the target URI for the Resend service. Sources: src/Resend/ResendClientOptions.cs:5-8
Property Definitions
The following table describes the primary configuration properties:
| Property | Type | Description |
|---|---|---|
ApiToken | string | The API key obtained from the Resend Dashboard used for authentication. |
ApiUrl | string | The base URL for the Resend API. Defaults to https://api.resend.com/. |
The diagram above illustrates the structure of the configuration object used to boot the Resend client. Sources: src/Resend/ResendClientOptions.cs:5-23
Dependency Injection Setup
The SDK integrates with IServiceCollection through the ResendDiExtensions class. This provides a fluent interface to register the IResend client within the application's service container. Sources: src/Resend/ResendDiExtensions.cs:8-10
Registration Methods
You register the Resend services using the AddResend method. This method accepts an optional configuration delegate to set properties on the ResendClientOptions instance. Sources: src/Resend/ResendDiExtensions.cs:18-28
- Call
builder.Services.AddResend()in your application startup. - Provide an action to assign the
ApiToken. - Inject
IResendinto your classes to perform operations.
Sources: README.md:50-54, src/Resend/ResendDiExtensions.cs:18-20
The sequence shows how the application startup configures the options object before the SDK client is registered in the DI container. Sources: src/Resend/ResendDiExtensions.cs:18-40, README.md:50-56
Environment Variable Integration
The library supports retrieval of sensitive tokens from environment variables. This is the recommended approach to prevent hard-coding credentials in source code. Sources: README.md:53, src/Resend/README.md:43
// Example configuration using environment variables
builder.Services.AddResend( o =>
{
o.ApiToken = Environment.GetEnvironmentVariable( "RESEND_APITOKEN" )!;
} );
Sources: README.md:50-54
Usage with IResend
Once configured, the IResend interface provides access to all SDK modules, including Email, Domains, API Keys, and Audiences. The client uses the configured ApiToken for every request defined in the interface. Sources: src/Resend/IResend.cs:10-25, src/Resend/README.md:15-30
The flowchart demonstrates the relationship between the configuration options and the functional modules accessible via the client interface. Sources: src/Resend/IResend.cs:6-100, src/Resend/ResendClientOptions.cs:5-8
Summary
Configuration Options provide the necessary foundation for the Resend .NET SDK by defining authentication and endpoint parameters. Through the ResendClientOptions class and AddResend extension methods, developers can securely integrate Resend services into their .NET applications using standard dependency injection practices. This architecture ensures that all API requests are properly authenticated and directed to the correct service URL. Sources: src/Resend/ResendClientOptions.cs, src/Resend/ResendDiExtensions.cs, README.md