Ruby SDK
Install and use the official Taifa Mail Ruby SDK to send email, manage domains, contacts, suppressions, templates, and webhooks.
The Taifa Mail Ruby SDK is a thin, idiomatic wrapper over the Mailer API. It ships as the taifa-mail gem on RubyGems and exposes one client object with a resource accessor per API group.
Source: github.com/GovConnectKenya/taifa-mail-sdks/tree/main/packages/ruby
Installation
The gem requires Ruby 3.0 or newer and has zero runtime dependencies (it uses net/http from the standard library).
Install it directly:
Or add it to your Gemfile:
Then run bundle install.
Client setup
Construct a client with your API key. The key starts with tfm_k_ and is passed on every request as a bearer token.
Never hard-code your API key. Load it from an environment variable or a secrets manager.
The constructor accepts these options:
| Option | Type | Default | Description |
|---|---|---|---|
api_key | String | (required) | Your API key. Must start with tfm_k_. |
base_url | String | https://govconnect.ke | API base URL. Override for a self-hosted or staging environment. |
max_retries | Integer | 3 | Retry attempts for 429 and 5xx responses, with exponential backoff that honours Retry-After. |
timeout | Numeric | 30 | Per-request open and read timeout, in seconds. |
The client exposes six resources: client.emails, client.domains, client.contacts, client.suppressions, client.templates, and client.webhooks.
Send an email
client.emails.send accepts keyword arguments (or a Hash). You pass a clean from, which the SDK maps to the API's from_ wire field. Anywhere an address is expected you may pass a bare string (treated as { email: ... }) or a Hash with email and an optional name.
Responses are plain Ruby Hashes with symbol keys. A send returns:
to, cc, and bcc each accept a single address or an array of addresses. Additional supported keys include reply_to, headers, tags, send_at (a Time or ISO 8601 string, for scheduled delivery), and attachments.
Emails
Domains
Contacts
Bulk send subject and bodies support {{email}}, {{name}}, and {{metadata_key}} placeholders.
Suppressions
The suppression list endpoints return a paginated envelope ({ items:, total:, page:, limit: }). The email argument maps to the API's email_address wire field.
Templates
Reusable templates are available on the Starter plan and above. For this resource only, html maps to html_body and text maps to text_body.
The variables field is derived server-side from {{name}} placeholders, so you do not pass it.
Webhooks
The deliveries listing returns a paginated envelope ({ items:, total:, page:, limit: }).
Error handling
Any non-2xx response (and any transport failure that survives every retry) raises Taifa Mail::Mailer::Error. Inspect #status, #code, and #message to branch on specific failures. A #status of 0 indicates a network or transport failure with no HTTP response, and #detail holds the raw parsed response body for debugging.
| Reader | Type | Description |
|---|---|---|
#status | Integer | HTTP status code. 0 for transport or network failures. |
#code | String, nil | Machine-readable error code from the API body, when present. |
#message | String | Human-readable error message. |
#detail | Object, nil | The raw parsed response body. |
The SDK retries 429 and 5xx responses automatically (up to max_retries), honouring Retry-After. Client errors in the 4xx range are never retried and surface immediately.
Configuration
All configuration is passed to the constructor. There is no global or file-based config.
base_urlis useful for pointing the client at a staging environment.max_retriesandtimeouttune the network behaviour for your workload.- Multipart uploads (
upload_csv,bulk_upload) are not retried, because uploads are not idempotent.
Next steps
- SDKs overview for the full list of official SDKs.
- Emails API reference for endpoint-level detail, request shapes, and limits.