.NET SDK
Send email, manage domains, contacts, templates, and webhooks from .NET with the official TaifaMail.Sdk package for C#.
The official .NET SDK is published as TaifaMail.Sdk on NuGet. Source lives in the taifa-mail-sdks repository.
The package targets net8.0 and netstandard2.0, so it works across modern .NET, .NET Framework, Xamarin, and Unity. Every API call is async and returns a Task.
Installation
You can also add it through the NuGet Package Manager or by adding a <PackageReference> to your .csproj.
Client setup
Create an API key in the dashboard under Settings -> API Keys. Keys start with tfm_k_. Construct the client with that key:
The constructor accepts these parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey | string | (required) | Your API key. Starts with tfm_k_. |
baseUrl | string? | https://govconnect.ke | Override the API base URL. A trailing slash is trimmed automatically. |
httpClient | HttpClient? | null | Supply your own HttpClient (recommended under dependency injection). One is created and owned otherwise. |
maxRetries | int | 3 | Total attempts on 429 / 5xx, including the first. |
TaifaMail implements IDisposable. It disposes the underlying HttpClient only when it created the client itself. When you pass your own HttpClient (for example one managed by IHttpClientFactory), the SDK leaves its lifetime to you.
Send an email
Emails.SendAsync queues a single message and returns its id and initial status. Use an object initializer to build the SendEmail; the To collection is initialized for you, so you can add recipients directly.
The returned SendEmailResult carries:
| Field | Type | Description |
|---|---|---|
Id | string | The message id. |
Status | string | Initial status, for example queued or scheduled. |
MessageId | string? | RFC 5322 Message-ID, once assigned. |
RejectionReason | string? | Reason the message was rejected, if it was. |
A few conveniences worth knowing:
Addressconverts implicitly from a bare email string, soTo = { "customer@example.com" }is shorthand forTo = { new Address("customer@example.com") }. Usenew Address(email, name)when you want a display name.- The SDK exposes a clean
Fromproperty and maps it to the wire fieldfrom_for you. You never writefrom_. - Provide
Html,Text, or both. SendAtis aDateTimeOffset?; set it to schedule the message for later (Starter plan and up). It is serialized as UTC ISO 8601.
The client also exposes a shortcut taifamail.SendAsync(...) that forwards to Emails.SendAsync.
Emails
Accessed as client.Emails.
Scheduled emails:
Saved searches (named filter sets stored per user) are returned as raw JsonElement values:
Domains
Accessed as client.Domains.
Contacts
Subscriber lists, their contacts, CSV imports, and templated bulk sends. Accessed as client.Contacts.
UploadCsvAsync takes the raw file bytes and a filename, sent as a single multipart field named file. The email column is auto-detected; other columns become contact metadata.
BulkSendAsync mails a templated message to every contact in a list. Subject, html, and text may use {{email}}, {{name}}, and {{metadata_key}} placeholders:
Suppressions
The do-not-send list. ListAsync returns a paginated Page<Suppression> envelope (Items, Total, Page, Limit). Accessed as client.Suppressions.
Templates
Reusable email templates (Starter plan and up). The SDK's html / text arguments map to the wire fields html_body / text_body for you. Accessed as client.Templates.
A template's variables are derived server-side from the {{name}} placeholders in its bodies, so you do not pass them when creating or updating.
Webhooks
Accessed as client.Webhooks.
Error handling
Every non-2xx response, and any transport failure that survives all retries, throws an TaifaMailException. Inspect Status and Code to branch on specific failures.
TaifaMailException.Status is 0 when no response was received (a transport or network failure that exhausted all retries). Code is populated from the API's detail body when present, and is null otherwise.
Configuration
- Retries. Requests that return
429or5xxare retried with exponential backoff, honoring theRetry-Afterheader when present. Control the total attempt count (including the first) withmaxRetries(default3). Multipart uploads (CSV and suppression imports) are not retried because they are not idempotent. - Custom
HttpClient. Pass your ownHttpClient, for example one fromIHttpClientFactory, to share connection pooling and integrate with dependency injection. The SDK sets theAuthorizationheader and base address on first use and does not dispose a client it did not create. - Custom base URL. Point the client at a staging or self-hosted host with the
baseUrlparameter. A trailing slash is trimmed automatically.
Pass a CancellationToken to any method to cancel an in-flight request:
Next steps
- SDKs overview for the full list of official SDKs.
- Emails API reference for the underlying HTTP endpoints, fields, and limits.