.NET SDK
The official CamelMailer NuGet package is a modern async client with first-class ASP.NET Core dependency injection. .NET 8+.
Install
terminal
dotnet add package CamelMailer
Quickstart
Program.cs
using CamelMailer;
using var camelmailer = new CamelMailerClient("cm_xxxx");
var result = await camelmailer.Emails.SendAsync(new SendEmailRequest
{
From = "billing@acme.com",
To = ["ada@example.com"],
Subject = "Your receipt",
HtmlBody = "<p>Thanks for your purchase.</p>",
});
Console.WriteLine($"Queued message {result.MessageId}");Dependency injection
Register the client once and inject ICamelMailerClient anywhere:
Program.cs
builder.Services.AddCamelMailer(options =>
{
options.ApiKey = builder.Configuration["CamelMailer:ApiKey"]!;
// options.BaseUrl = "https://mail.example.com"; // self-hosted
});ReceiptService.cs
public class ReceiptService(ICamelMailerClient camelmailer)
{
public Task SendReceiptAsync(string to, CancellationToken ct) =>
camelmailer.Emails.SendAsync(new SendEmailRequest
{
From = "billing@acme.com",
To = [to],
Subject = "Your receipt",
TextBody = "Thanks for your purchase.",
}, ct);
}Send with a template
Template.cs
await camelmailer.Emails.SendWithTemplateAsync(new SendTemplateEmailRequest
{
From = "hello@acme.com",
To = ["ada@example.com"],
Template = "welcome",
TemplateModel = new Dictionary<string, object?> { ["name"] = "Ada" },
});Error handling
The SDK throws typed exceptions: CamelMailerNetworkException when no response arrives, CamelMailerException when the API returns an error envelope.
Errors.cs
try
{
await camelmailer.Emails.SendAsync(request);
}
catch (CamelMailerNetworkException ex)
{
// DNS failure, refused connection, timeout — no API response
Console.WriteLine($"Network problem: {ex.InnerException?.Message}");
}
catch (CamelMailerException ex)
{
// The API answered with an error envelope
Console.WriteLine($"{ex.ErrorCode} (HTTP {(int?)ex.StatusCode}): {ex.Message}");
}Self-hosted instances
The client talks to the cloud (https://app.camelmailer.com) by default. Pass a base URL to point at your own installation:
SelfHosted.cs
using var camelmailer = new CamelMailerClient("cm_xxxx", "https://mail.example.com");Full field reference: Messages API.
