Rust SDK

The Rust SDK is async-first and uses reqwest.

Install

[dependencies]
workonward = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Rust 1.75+ is supported.

Send

use std::env;
use workonward::{Client, SendOptions};
 
#[tokio::main]
async fn main() -> Result<(), workonward::Error> {
    let client = Client::new(env::var("WORKONWARD_API_KEY").unwrap())?;
 
    let result = client
        .send("user@example.com", SendOptions::default())
        .await?;
 
    println!("{} {}", result.message_id, result.engine);
    Ok(())
}

Send With Attributes

use std::collections::HashMap;
use workonward::SendOptions;
 
let options = SendOptions {
    attribs: HashMap::from([
        ("first_name".to_string(), "Ada".to_string()),
    ]),
    ..SendOptions::default()
};
 
let result = client.send("user@example.com", options).await?;

Batch Send

let recipients = vec![
    "ada@example.com".to_string(),
    "grace@example.com".to_string(),
];
 
let result = client
    .send_batch(&recipients, SendOptions::default())
    .await?;
 
println!("{} {:?}", result.accepted, result.message_ids);

Options

use std::time::Duration;
use workonward::{Client, RetryConfig};
 
let mut retry = RetryConfig::disabled();
retry.max_retries = 2;
 
let client = Client::builder(std::env::var("WORKONWARD_API_KEY").unwrap())
    .base_url("https://mail.gitdate.ink/api")
    .timeout(Duration::from_secs(10))
    .retry_config(retry)
    .build()?;

Error Handling

match client.send("user@example.com", SendOptions::default()).await {
    Ok(result) => println!("{}", result.message_id),
    Err(workonward::Error::Authentication(ctx)) => {
        eprintln!("API key rejected: {:?}", ctx.code);
    }
    Err(workonward::Error::InvalidRecipient(ctx)) => {
        eprintln!("Bad recipient: {}", ctx.message);
    }
    Err(error) => eprintln!("Send failed: {error}"),
}

Each error variant exposes structured context through code(), status_code(), response_data(), and response_text().