Duta.Net
0.2.0
dotnet add package Duta.Net --version 0.2.0
NuGet\Install-Package Duta.Net -Version 0.2.0
<PackageReference Include="Duta.Net" Version="0.2.0" />
<PackageVersion Include="Duta.Net" Version="0.2.0" />
<PackageReference Include="Duta.Net" />
paket add Duta.Net --version 0.2.0
#r "nuget: Duta.Net, 0.2.0"
#:package Duta.Net@0.2.0
#addin nuget:?package=Duta.Net&version=0.2.0
#tool nuget:?package=Duta.Net&version=0.2.0
Duta.Net
The official .NET SDK for Duta, transactional email for Malaysia.
- .NET 8+. Async throughout, with
CancellationToken. services.AddDuta(...)for ASP.NET Core and any host with dependency injection.- Retries rate limits and server errors safely: every send carries an idempotency key, so a retry can never send twice.
Upgrading from 0.1.x
0.2.0 is a new SDK for Duta's current API, not an update of 0.1.x, which was written for an earlier version of Duta that no longer runs.
Install
dotnet add package Duta.Net
ASP.NET Core
builder.Services.AddDuta(o => o.ApiKey = builder.Configuration["Duta:ApiKey"]);
Then inject DutaClient wherever you send mail:
app.MapPost("/orders/{id}/receipt", async (string id, DutaClient duta) =>
{
var sent = await duta.Emails.SendAsync(new SendEmailRequest
{
From = "Kedai <resit@kedai.my>",
To = ["siti@example.com"],
Subject = "Resit #1042",
Html = "<p>Terima kasih.</p>",
}, new SendOptions(IdempotencyKey: $"receipt-{id}"));
return sent.Id;
});
Without dependency injection
var duta = new DutaClient(Environment.GetEnvironmentVariable("DUTA_API_KEY"));
var sent = await duta.Emails.SendAsync(email);
Keep one DutaClient for the life of the app. Errors throw DutaException:
Code is Duta's error code and
RequestId finds the request on the Logs screen.
try
{
await duta.Emails.SendAsync(email);
}
catch (DutaException e)
{
logger.LogError("Send failed: {Code} {RequestId}", e.Code, e.RequestId);
}
Batch and paging
await duta.Batch.SendAsync([first, second], new BatchOptions(Validation: "permissive"));
await foreach (var email in duta.Emails.ListAllAsync(new EmailListParams { Status = "bounced" }))
Console.WriteLine(email.Id);
Verify webhooks
var body = await new StreamReader(Request.Body).ReadToEndAsync(); // the raw body
var evt = WebhookSignature.Verify(
body,
Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString()),
configuration["Duta:WebhookSecret"]);
It throws WebhookVerificationException when the signature is wrong or the
delivery is more than five minutes old.
Everything else
Emails |
SendAsync, GetAsync, ListAsync, ListAllAsync |
Batch |
SendAsync |
Domains |
CreateAsync, ListAsync, GetAsync, VerifyAsync, RemoveAsync |
ApiKeys |
CreateAsync, ListAsync, RemoveAsync |
Webhooks |
CreateAsync, ListAsync, GetAsync, RemoveAsync, EnableAsync, TestAsync, DeliveriesAsync, Verify |
Suppressions |
CreateAsync, ListAsync, ListAllAsync, RemoveAsync |
Logs |
ListAsync, ListAllAsync, GetAsync |
Usage |
GetAsync |
Options: new DutaClientOptions { ApiKey, BaseUrl, MaxRetries = 2, Timeout = 30s }.
Full documentation: https://docs.duta.indra.sh
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.