.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.
