Rust SDK
Async Rust SDK for Taifa Mail. Send transactional and bulk email, manage domains, contacts, suppressions, templates, and webhooks.
The Taifa Mail Rust SDK is published as the taifa-mail crate on crates.io. It is an async client built on reqwest and serde, with a single transport layer that owns bearer authentication, JSON encoding, retries on 429 and 5xx (honouring Retry-After), and error mapping to a typed TaifaMailError.
Source lives in the taifa-mail-sdks repository.
Installation
Add the crate with cargo:
The client is async, so you also need a runtime. We use tokio throughout the examples:
Every SDK call is a future. You must .await it inside an async runtime such as tokio or async-std. The examples below use #[tokio::main].
Client setup
Construct a client with your API key. Keys start with tfm_k_ and are passed as a bearer token on every request.
Taifa Mail::new uses the defaults: base URL https://govconnect.ke, 3 total attempts on retryable failures, and a 30 second per-request timeout. To override any of these, use the builder:
| Option | Method | Default | Description |
|---|---|---|---|
| Base URL | .base_url(...) | https://govconnect.ke | Override the API host (trailing slashes are trimmed). |
| Max retries | .max_retries(u32) | 3 | Total attempts on 429 / 5xx, including the first. Floored at 1. |
| Timeout | .timeout(Duration) | 30 seconds | Per-request timeout. |
Resources are reached through accessor methods on the client: client.emails(), client.domains(), client.contacts(), client.suppressions(), client.templates(), and client.webhooks(). The client is Clone and cheap to share across tasks.
Send an email
A full, runnable example. SendEmail::builder takes the sender, recipients, and subject, then chained setters add the body and optional fields. Every send returns Result<SendEmailResponse, TaifaMailError>.
The sender and each recipient are an Address. There is sugar so you rarely build one by hand:
- A bare
&strorStringbecomes{ email }(viaFrom<&str>). - A
(&str, &str)tuple becomes{ email, name }. - Anywhere a recipient list is expected (
to,cc,bcc), a single address or aVecof them both work, thanks toIntoAddressList.
On the wire the sender field is serialized as from_ (with a trailing underscore). The SDK hides that quirk: you always work with a clean from argument and Address.
Emails
The emails() resource sends, looks up, searches, schedules, and inspects messages.
Domains
The domains() resource registers, verifies, inspects, and transfers sending domains.
Contacts
The contacts() resource manages subscriber lists, individual contacts, CSV imports, and templated bulk sends.
Suppressions
The suppressions() resource manages the do-not-send list. Its list endpoint returns a paginated Page<Suppression> envelope rather than a bare array.
Templates
The templates() resource manages reusable templates (Starter plan and up). On the wire html and text map to html_body and text_body; the SDK exposes the clean names.
Webhooks
The webhooks() resource manages event subscriptions and inspects deliveries. The delivery list returns a paginated Page<WebhookDelivery> envelope.
Error handling
Every fallible call returns Result<T, TaifaMailError> (the crate also exports a Result<T> alias). TaifaMailError is raised for any non-2xx response or for a transport failure that survives all retries. It implements std::error::Error and Display, so it composes with ? and the wider error ecosystem.
Branch on status and code to handle specific failures:
A status of 0 indicates a transport or network failure with no HTTP response. The transport already retries 429 and 5xx responses (honouring Retry-After) up to max_retries, so an error reaching your code means the retries were exhausted.
Configuration
| Setting | Where | Default | Notes |
|---|---|---|---|
| API key | Taifa Mail::new(key) / Taifa Mail::builder(key) | required | Must be a valid tfm_k_ key; passed as a bearer token. |
| Base URL | .base_url(...) | https://govconnect.ke | Trailing slashes trimmed. |
| Max retries | .max_retries(u32) | 3 | Total attempts on 429 / 5xx. Floored at 1. |
| Timeout | .timeout(Duration) | 30 seconds | Per-request timeout via reqwest. |
Read the API key from the environment rather than hard-coding it:
Never commit API keys. Load them from environment variables or a secrets manager, and scope each key to the minimum permissions it needs.
Next steps
- SDK overview for the full list of official SDKs.
- Emails API reference for the underlying REST endpoints, request shapes, and status codes.