C# / .NET SDK
The official Harbur .NET client. Compatible with .NET 6, 7, 8, .NET Standard 2.0/2.1, and C# 10+. Fully asynchronous and thread-safe.
.NET 6 / 7 / 8 / 9NuGet: HarburAsync / Task-based
Installation
bash
dotnet add package HarburOr via Package Manager:
powershell
Install-Package HarburBasic Usage
Initialize the client. It automatically detects HARBUR_API_KEY from the environment.
Program.cs
using Harbur;
// Automatically reads HARBUR_API_KEY from environment
var client = new HarburClient();
var response = await client.Emails.SendAsync(new SendEmailOptions
{
From = "support@yourdomain.com",
To = new List<string> { "customer@example.com" },
Subject = "Welcome to Harbur!",
Html = "<h1>Welcome aboard!</h1><p>Transactional email sent via C#.</p>",
Text = "Welcome aboard! Transactional email sent via C#."
});
Console.WriteLine($"Dispatched Message ID: {response.Id}");Note
Set
HARBUR_API_KEY in your appsettings.json or environment variables.CC, BCC & Custom Reply-To
Advanced.cs
using Harbur;
var client = new HarburClient();
var response = await client.Emails.SendAsync(new SendEmailOptions
{
From = "support@yourdomain.com",
To = new List<string> { "client@example.com" },
Cc = new List<string> { "accounting@example.com" },
Bcc = new List<string> { "archive@example.com" },
ReplyTo = "helpdesk@yourdomain.com",
Subject = "Invoice #1042 Ready",
Html = "<p>Your monthly statement is ready.</p>"
});File Attachments
Attach PDF invoices or spreadsheets by passing raw byte[] with Attachment.FromBytes:
Attachments.cs
using Harbur;
var client = new HarburClient();
byte[] pdfBytes = await File.ReadAllBytesAsync("invoice.pdf");
var response = await client.Emails.SendAsync(new SendEmailOptions
{
From = "billing@yourdomain.com",
To = new List<string> { "client@example.com" },
Subject = "Your Invoice #1042",
Html = "<p>Please find your receipt attached below.</p>",
Attachments = new List<Attachment>
{
Attachment.FromBytes("invoice_1042.pdf", pdfBytes, "application/pdf")
}
});ASP.NET Core Integration
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Register singleton
builder.Services.AddSingleton(new HarburClient(builder.Configuration["Harbur:ApiKey"]));
var app = builder.Build();
app.MapPost("/api/send-receipt", async (HarburClient harbur, SendEmailOptions opts) =>
{
var res = await harbur.Emails.SendAsync(opts);
return Results.Ok(new { success = true, id = res.Id });
});
app.Run();