Java SDK
Send email, manage domains, contacts, templates, and webhooks from the JVM with the official ke.govconnect:taifa-mail-sdk SDK.
The official Java SDK is published under the Maven coordinates ke.govconnect:taifa-mail-sdk on Maven Central. Source lives in the taifa-mail-sdks repository.
The SDK has a small dependency footprint (Jackson for JSON), uses the built-in java.net.http.HttpClient, and targets Java 11 and later.
Installation
Gradle (Kotlin DSL):
Maven:
The SDK requires Java 11 or later. It uses the JDK's built-in java.net.http.HttpClient, so there is no third-party HTTP client to configure.
Client setup
Create an API key in the dashboard under Settings -> API Keys. Keys start with tfm_k_. Construct the client with that key:
An overloaded constructor lets you override the base URL and the retry count:
| Constructor argument | Type | Default | Description |
|---|---|---|---|
apiKey | String | (required) | Your API key. Starts with tfm_k_. Must not be blank. |
baseUrl | String | https://govconnect.ke | Override the API base URL. A trailing slash is trimmed automatically. |
maxRetries | int | 3 | Total attempts on 429 / 5xx, including the first. Clamped to at least 1. |
Resources are exposed as accessor methods that share a single transport: taifamail.emails(), taifamail.domains(), taifamail.contacts(), taifamail.suppressions(), taifamail.templates(), and taifamail.webhooks().
Send an email
emails().send(...) queues a single message and returns its id and initial status. Build the message with SendEmail.builder().
The returned SendEmailResult has these fields:
| Field | Type | Description |
|---|---|---|
id | String | The queued message id. |
status | String | Initial status, typically queued. |
messageId | String | The SMTP Message-ID, wire field message_id. May be null. |
rejectionReason | String | Why the message was rejected, wire field rejection_reason. Null when accepted. |
A few conveniences worth knowing:
- The builder exposes a clean
from(...)and maps it to the wire fieldfrom_for you. You never writefrom_. from,to,cc,bcc, andreplyToaccept a bare email string, or an email plus a display name.tocan be called more than once to add multiple recipients.- Provide
html,text, or both. sendAt(Instant)schedules the message for later delivery (Starter plan and up).
TaifaMail also provides a shortcut taifamail.send(email) that delegates to emails().send(email).
Emails
Scheduled emails:
Saved searches (named filter sets stored per user) are exposed as open maps:
Domains
Contacts
Subscriber lists, their contacts, CSV imports, and templated bulk sends.
uploadCsv 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.
bulkSend mails a templated message to every contact in a list. Subject, html, and text may use {{email}}, {{name}}, and {{metadata_key}} placeholders. The contact_list_id wire field is set from the list id automatically.
Suppressions
The do-not-send list. list returns a paginated Page envelope (items, total, page, limit).
Templates
Reusable email templates (Starter plan and up). html maps to the wire field html_body and text to text_body for you.
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
Error handling
Every non-2xx response, and any transport failure that survives all retries, throws an TaifaMailException (an unchecked RuntimeException). Inspect getStatus() and getCode() to branch on specific failures.
Configuration
- Retries. Requests that return
429or5xxare retried with exponential backoff, honouring theRetry-Afterheader when present. Control the total attempt count (including the first) with themaxRetriesconstructor argument (default3). Multipart uploads (uploadCsv,bulkUpload) are not retried because they are not idempotent. - Timeout. Each request has a 30-second timeout and a 15-second connect timeout. A timeout is treated as a transport failure and is retried while attempts remain.
- Custom base URL. Point the client at a staging or self-hosted host with the second constructor argument. A trailing slash is trimmed automatically.
Next steps
- SDKs overview for the full list of official SDKs.
- Emails API reference for the underlying HTTP endpoints, fields, and limits.