Senviok Rust SDK
Official async Rust client for the Senviok messaging API.
Send transactional email, SMS, and WhatsApp from one client, and manage the resources around them: templates, sending domains, audiences, contacts, suppressions, webhooks, and delivery logs.
let client = new;
let sent = client
.emails
.send
.await?;
println!;
Features
- Async
tokioclient overreqwest - Bearer-token auth against
https://api.senviok.live - Typed request/response models with
serde - Structured errors for HTTP, decode, and API failures
- Override the base URL for staging or self-hosted environments
Install
Add the crate to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
From a local checkout:
[]
= { = "../sendvoik-rust-client" }
Requires a recent stable Rust toolchain (this crate uses edition 2024).
Authentication
Create an API key in the Senviok dashboard, then pass it to Senviok::new. The client sends it as a Bearer token on every request.
use Senviok;
let client = new;
Keep keys out of source control. Copy .env.example to .env for the examples; they load SENVIOK_API_KEY (and other vars) from the environment.
To point at a different API host:
let client = new
.with_base_url;
Quick start
use ;
async
Run the bundled example:
Resources
| Resource | Methods |
|---|---|
emails |
send |
sms |
send |
whatsapp |
send |
templates |
create, list, get, update, delete |
domains |
create, list, get_dkim, verify |
audiences |
create, list, delete |
contacts |
create, list, delete |
suppressions |
create, list, delete |
messages |
list |
webhooks |
create, list, logs, delete |
Every method returns Result<T, SenviokError>.
SendEmailRequest implements Default, so you only set the fields you need. Required: from, to, subject. Provide html, text, or a template_id.
use ;
use json;
let client = new;
// HTML + plaintext
client
.emails
.send
.await?;
// Template with merge data
client
.emails
.send
.await?;
Optional fields: from_name, cc, bcc, reply_to, html, text, template_id, template_data, add_unsubscribe_footer, add_list_unsubscribe_header.
SMS
use ;
client
.sms
.send
.await?;
use ;
client
.whatsapp
.send
.await?;
Email, SMS, and WhatsApp all return SendMessageResponse { id }.
Templates
Reusable HTML email templates.
use ;
let template = client
.templates
.create
.await?;
let listed = client.templates.list.await?;
let one = client.templates.get.await?;
client
.templates
.update
.await?;
client.templates.delete.await?;
Domains
Register a sending domain, fetch DKIM records, then verify DNS.
use CreateDomainRequest;
let domain = client
.domains
.create
.await?;
let dkim = client.domains.get_dkim.await?;
let status = client.domains.verify.await?;
println!;
let all = client.domains.list.await?;
Audiences & contacts
Audiences are lists. Contacts belong to an audience.
use ;
let audience = client
.audiences
.create
.await?;
let contact = client
.contacts
.create
.await?;
let members = client.contacts.list.await?;
client.contacts.delete.await?;
client.audiences.delete.await?;
Suppressions
Block an address from receiving further mail.
use CreateSuppressionRequest;
let entry = client
.suppressions
.create
.await?;
let blocked = client.suppressions.list.await?;
client.suppressions.delete.await?;
Message logs
Query delivery history with optional filters. All fields on ListMessagesQuery are optional.
use ListMessagesQuery;
let logs = client
.messages
.list
.await?;
for log in logs
Filters: take, skip, sort_order, channel, status, to_address, from_address, subject, start_date, end_date.
Webhooks
Subscribe to delivery events, inspect recent deliveries, then tear the endpoint down.
use CreateWebhookRequest;
let hook = client
.webhooks
.create
.await?;
println!;
let endpoints = client.webhooks.list.await?;
let deliveries = client.webhooks.logs.await?;
client.webhooks.delete.await?;
Store hook.secret when the webhook is created — you need it to verify inbound signatures on your server.
Error handling
All fallible calls return SenviokError:
use SenviokError;
match client.emails.send.await
| Variant | When |
|---|---|
Api { status, message, body } |
Non-success HTTP status. message is parsed from the JSON body when present; body is the raw response. |
Request |
Network / TLS / reqwest failure. |
Decode |
Response body was not valid JSON for the expected type. |
SenviokError implements std::error::Error via thiserror, so it works with ? and anyhow / eyre.
Client API
new
with_base_url // builder; default https://api.senviok.live
client.emails
client.sms
client.whatsapp
client.templates
client.domains
client.audiences
client.contacts
client.suppressions
client.messages
client.webhooks
The crate re-exports the client, error type, and all request/response models from the crate root:
use ;
Examples
Copy .env.example to .env and fill in your key (and any addresses you want to send to).
| Example | What it does | Extra env |
|---|---|---|
send_email |
Send a transactional email | SENVIOK_FROM_EMAIL, SENVIOK_TO_EMAIL |
send_sms |
Send an SMS | SENVIOK_FROM_SMS, SENVIOK_TO_PHONE |
send_whatsapp |
Send a WhatsApp message | SENVIOK_FROM_WHATSAPP or SENVIOK_FROM_SMS, SENVIOK_TO_PHONE |
templates |
Create, list, update, delete a template | — (cleans up after itself) |
domains |
List domains; optionally create + DKIM + verify | SENVIOK_DOMAIN to mutate |
audiences |
Create an audience, add a contact, clean up | SENVIOK_CONTACT_EMAIL (optional) |
suppressions |
Add, list, then remove a suppression | SENVIOK_SUPPRESSION_EMAIL (optional) |
list_messages |
Print recent delivery logs | SENVIOK_CHANNEL, SENVIOK_STATUS (optional) |
webhooks |
List webhooks; optionally create, inspect, delete | SENVIOK_WEBHOOK_URL to mutate |
send_email, send_sms, and send_whatsapp hit the live API and deliver a real message. The template / audience / suppression examples create records and delete them before exiting.
Publishing to crates.io
This is a library crate. You do not deploy a server — you publish it so other Rust projects can depend on it with cargo add senviok.
Before the first publish
- Create a crates.io account (GitHub login) and run
cargo login, pasting the API token from crates.io/me. - Push this repo to GitHub, then uncomment and set
repositoryinCargo.toml. crates.io and docs.rs use that URL. - Confirm the license. This repo ships MIT; change
LICENSEand thelicensefield if you need Apache-2.0 or dual-license. - Bump
versioninCargo.tomlfor every release (semver: breaking API →0.2.0/1.0.0, compatible additions →0.1.1).
Publish
cargo publish --dry-run packs the crate and checks it without uploading. The real cargo publish is permanent for that version — you cannot overwrite 0.1.0, only yank it.
After publish, docs build automatically at docs.rs/senviok.
GitHub Packages / private registries are a different path (cargo publish --registry). For an official public SDK, crates.io is the one you want.
Development
CI (.github/workflows/ci.yml) runs rustfmt, clippy, tests, and rustdoc on push and pull request.
License
MIT. See LICENSE.