Go SDK
Official Go SDK for the Taifa Mail API. Send email, manage domains, contacts, suppressions, templates, and webhooks with a typed, idiomatic client.
The Taifa Mail Go SDK is a typed, idiomatic client for the Taifa Mail API. It wraps every Core resource (emails, domains, contacts, suppressions, templates, and webhooks) behind a single Client, handles bearer authentication, JSON encoding, and retries, and maps every API error to a single *Error type.
The module is github.com/GovConnectKenya/taifa-mail-go and lives in its own repository: github.com/GovConnectKenya/taifa-mail-go.
Installation
The SDK requires Go 1.21 or later and depends only on the standard library.
The package name is taifamail, so you import it directly:
Client setup
Construct a client with taifamail.New, passing your API key. API keys start with tfm_k_ and are passed as a bearer token on every request.
New accepts variadic taifamail.Option values to override the defaults:
| Option | Default | Description |
|---|---|---|
taifamail.WithBaseURL(url string) | https://govconnect.ke | Override the API base URL. |
taifamail.WithMaxRetries(n int) | 3 | Total attempts on 429 and 5xx, including the first. |
taifamail.WithTimeout(d time.Duration) | 30s | Per-request timeout. |
taifamail.WithHTTPClient(hc *http.Client) | stdlib client | Inject a custom *http.Client for proxies or testing. |
The resources are reached as fields on the client: client.Emails, client.Domains, client.Contacts, client.Suppressions, client.Templates, and client.Webhooks. The client is safe for concurrent use.
Every method takes a context.Context as its first argument, so you can carry deadlines and cancellation through to the underlying HTTP request.
Send an email
The example below is a complete, runnable program. It builds a SendEmail, sends it, and prints the queued message id.
The From field is required and must be a registered sender on a verified domain. Provide HTML, Text, or both. taifamail.Addr("email@example.com") is a helper that builds an Address from a bare email string when you do not need a display name.
Send returns a *SendResult:
| Field | Type | Description |
|---|---|---|
ID | string | The queued email id. |
Status | string | Queue status, for example queued. |
MessageID | string | The RFC message id, when available. |
RejectionReason | string | Set when the message was rejected. |
Emails
To schedule a send for later, set SendAt on the SendEmail to an ISO 8601 timestamp (Starter plan and up).
Pagination is zero-based everywhere: Page: 0 is the first page.
Domains
The newly created Domain carries a DnsRecords slice. Publish each record's Host and Value, then call Verify to complete setup.
Contacts
BulkSend injects the list id as contact_list_id automatically, so you leave that field unset. Subject and body may use {{email}}, {{name}}, and {{metadata_key}} placeholders. Optional string fields on the params structs are pointers, so unset fields are omitted from the request.
Suppressions
Suppressions.List returns a *Page[Suppression], the generic envelope used by endpoints that paginate with a total count.
Templates
Variables on a Template are derived server-side from {{name}} placeholders and are read-only, so you do not pass them.
Webhooks
The signing Secret is generated by the API and returned in plaintext on every read of a Webhook.
Error handling
Every method returns an error that, on any non-2xx response or a transport failure that survives all retries, is an *taifamail.Error. Type-assert to inspect it:
The Error struct has three fields:
| Field | Type | Description |
|---|---|---|
Status | int | The HTTP status code. 0 means a transport or network failure where no response was received. |
Code | string | The machine-readable error code from the API body, when present. |
Message | string | A human-readable description of the failure. |
Configuration
Retries. The client retries 429 and 5xx responses, as well as transient network failures, up to WithMaxRetries total attempts (default 3). Backoff is exponential starting at 250ms and honors a Retry-After header when the API sends one. Other 4xx responses are never retried. Multipart uploads (UploadCSV, BulkUpload) are not retried because they are not idempotent.
Timeout. WithTimeout sets the per-request timeout (default 30s). For finer control, pass a context.Context with its own deadline; the retry loop respects context cancellation between attempts.
Base URL. WithBaseURL overrides the API host (default https://govconnect.ke). A trailing slash is trimmed for you.
Next steps
- SDKs overview for the full list of official SDKs and shared conventions.
- Emails API reference for the underlying HTTP endpoints, request fields, and response shapes.