https://github.com/christian-schou/usesend-dotnet
Unofficial useSend .NET SDK, written in C#
https://github.com/christian-schou/usesend-dotnet
csharp dotnet email usesend usesend-dotnet usesend-net
Last synced: 10 days ago
JSON representation
Unofficial useSend .NET SDK, written in C#
- Host: GitHub
- URL: https://github.com/christian-schou/usesend-dotnet
- Owner: Christian-Schou
- Created: 2026-05-28T09:22:18.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2026-05-28T13:18:11.000Z (10 days ago)
- Last Synced: 2026-05-28T13:23:50.045Z (10 days ago)
- Topics: csharp, dotnet, email, usesend, usesend-dotnet, usesend-net
- Language: C#
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# useSend .NET SDK
Unofficial .NET SDK for [useSend](https://usesend.com) — an open-source alternative to Resend, SendGrid, Mailgun, and Postmark.
[](https://github.com/Christian-Schou/usesend-dotnet/actions/workflows/ci.yml)
## Packages
| Package | NuGet | Description |
|---------|-------|-------------|
| `UseSend` | [](https://www.nuget.org/packages/UseSend) | Core SDK — send emails, manage domains, contacts, campaigns, and analytics |
| `UseSend.FluentEmail` | [](https://www.nuget.org/packages/UseSend.FluentEmail) | [FluentEmail](https://github.com/lukencode/FluentEmail) sender backed by useSend |
| `UseSend.Identity` | [](https://www.nuget.org/packages/UseSend.Identity) | ASP.NET Core Identity `IEmailSender` / `IEmailSender` backed by useSend |
| `UseSend.OpenTelemetry` | [](https://www.nuget.org/packages/UseSend.OpenTelemetry) | Distributed tracing (ActivitySource) and metrics (request count + duration) |
| `UseSend.Razor` | [](https://www.nuget.org/packages/UseSend.Razor) | Razor (.cshtml) template rendering via [RazorLight](https://github.com/toddams/RazorLight) |
| `UseSend.Webhooks` | [](https://www.nuget.org/packages/UseSend.Webhooks) | Webhook signature verification and typed event parsing |
---
## UseSend — Core SDK
```bash
dotnet add package UseSend
```
```csharp
// Program.cs
builder.Services.AddUseSend("us_your_api_token");
// Inject IUseSend or individual service interfaces (IEmailService, IDomainService, …)
public class WelcomeSender(IUseSend useSend)
{
public async Task SendAsync(string to)
{
var response = await useSend.Emails.SendAsync(new EmailMessage
{
From = "noreply@yourdomain.com",
To = to,
Subject = "Welcome!",
Html = "
Welcome aboard!
",
});
}
}
```
**Self-hosted useSend** — point the SDK at your own instance:
```csharp
builder.Services.AddUseSend(options =>
{
options.ApiToken = "us_your_api_token";
options.ApiUrl = "https://send.mycompany.com/api/";
});
```
| Resource | Operations |
|----------|-----------|
| **Emails** | Send, Batch send (with idempotency), Get, List, Cancel / Update schedule |
| **Domains** | List, Create, Get, Delete, Verify |
| **Contacts** | Create, Get, List, Update, Upsert, Delete, Bulk create / delete |
| **Contact Books** | List, Create, Get, Update, Delete |
| **Campaigns** | Create, Get, List, Delete, Schedule, Pause, Resume |
| **Analytics** | Email time series, Reputation metrics |
→ [Full documentation](src/UseSend/README.md)
---
## UseSend.Identity
ASP.NET Core Identity `IEmailSender` / `IEmailSender` — drop-in email sending for scaffolded Identity pages (confirm email, reset password, etc.).
```bash
dotnet add package UseSend
dotnet add package UseSend.Identity
```
```csharp
// Program.cs — typed (scaffolded Identity pages)
builder.Services.AddUseSend("us_your_api_token");
builder.Services.AddUseSendIdentityEmailSender(
fromAddress: "noreply@yourdomain.com",
fromName: "My App"
);
```
Default HTML templates are provided for confirmation links, password reset links, and reset codes. Override any method by subclassing `UseSendEmailSender`.
→ [Full documentation](src/UseSend.Identity/README.md)
---
## UseSend.FluentEmail
Drop-in [FluentEmail](https://github.com/lukencode/FluentEmail) sender — use the FluentEmail API you already know, delivered by useSend.
```bash
dotnet add package UseSend
dotnet add package UseSend.FluentEmail
```
```csharp
builder.Services.AddUseSend("us_your_api_token");
builder.Services
.AddFluentEmail("noreply@yourdomain.com")
.AddUseSendSender();
```
→ [Full documentation](src/UseSend.FluentEmail/README.md)
---
## UseSend.Webhooks
Verify webhook signatures and parse typed event payloads from useSend.
```bash
dotnet add package UseSend.Webhooks
```
```csharp
builder.Services.AddUseSendWebhooks(builder.Configuration["UseSend:WebhookSecret"]!);
app.MapPost("/webhooks/usesend", async (HttpRequest req, UseSendWebhooks webhooks) =>
{
var rawBody = await new StreamReader(req.Body).ReadToEndAsync();
var headers = req.Headers.ToDictionary(h => h.Key, h => h.Value.ToString());
var evt = webhooks.ConstructEvent(rawBody, headers); // throws WebhookException on bad/stale signature
if (evt.Type == WebhookEventType.EmailDelivered)
Console.WriteLine($"Delivered: {evt.GetData()?.Id}");
return Results.Ok();
});
```
Signatures use `HMAC-SHA256` with constant-time comparison and 5-minute replay protection.
| Group | Events |
|-------|--------|
| Email | `queued`, `sent`, `delivered`, `delivery_delayed`, `bounced`, `rejected`, `rendering_failure`, `complained`, `failed`, `cancelled`, `suppressed`, `opened`, `clicked` |
| Contact | `created`, `updated`, `deleted` |
| Domain | `created`, `verified`, `updated`, `deleted` |
→ [Full documentation](src/UseSend.Webhooks/README.md)
---
## UseSend.OpenTelemetry
Adds distributed tracing spans and metrics (request count + duration histogram) to every useSend API call.
```bash
dotnet add package UseSend.OpenTelemetry
```
```csharp
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddUseSendInstrumentation() // ActivitySource "UseSend"
.AddOtlpExporter())
.WithMetrics(metrics => metrics
.AddUseSendInstrumentation() // Meter "UseSend"
.AddOtlpExporter());
```
→ [Full documentation](src/UseSend.OpenTelemetry/README.md)
---
## UseSend.Razor
Compile and render strongly-typed Razor (.cshtml) templates as email HTML bodies using [RazorLight](https://github.com/toddams/RazorLight).
```bash
dotnet add package UseSend.Razor
```
```csharp
builder.Services.AddUseSendRazor("/path/to/email/templates");
// Inject IEmailTemplateRenderer and render before sending
var html = await renderer.RenderAsync("Emails/Welcome", new WelcomeModel { Name = "Alice" });
```
→ [Full documentation](src/UseSend.Razor/README.md)
---
## Requirements
- .NET 8 or .NET 10
- A [useSend](https://usesend.com) account or self-hosted instance
## Examples
| Example | Description |
|---------|-------------|
| [ConsoleNoDi](examples/ConsoleNoDi) | Standalone usage without dependency injection |
| [WebMinimalApi](examples/WebMinimalApi) | ASP.NET Core minimal API with DI |
| [ConsoleSelfHosted](examples/ConsoleSelfHosted) | Custom host URL for self-hosted useSend |
| [WebIdentity](examples/WebIdentity) | ASP.NET Core Identity — email confirmation and password reset |
| [WebHangfire](examples/WebHangfire) | Background email jobs via [Hangfire](https://www.hangfire.io/) |
| [WebMassTransit](examples/WebMassTransit) | Event-driven email via [MassTransit](https://masstransit.io/) `SendEmailCommand` consumer |
| [WebTemporal](examples/WebTemporal) | Durable email workflow with [Temporal.io](https://temporal.io/) |
## Contributing
PRs and issues welcome. Run tests with:
```bash
dotnet test
```
## License
MIT