SDK's

Rust

Officiële Rust SDK voor WeSender, beschikbaar als crate op crates.io. Gebouwd op reqwest met async/await via Tokio.

github.com/nljerry/wesender-rust

Installatie

Voeg toe aan je Cargo.toml:

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }

E-mail versturen

curl -X POST https://api.wesender.nl/emails \
  -H "Authorization: Bearer $WS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from":    "noreply@joudomein.nl",
    "to":      "klant@voorbeeld.nl",
    "subject": "Hallo van Rust!",
    "html":    "<p>Verstuurd via de Wesender API.</p>"
  }'

Herbruikbare client

use reqwest::Client;
use serde_json::{json, Value};
use std::error::Error;

pub struct WesenderClient {
    client:  Client,
    api_key: String,
}

impl WesenderClient {
    pub fn new(api_key: impl Into<String>) -> Self {
        Self { client: Client::new(), api_key: api_key.into() }
    }

    pub async fn send_email(&self, payload: Value) -> Result<Value, Box<dyn Error>> {
        let res = self.client
            .post("https://api.wesender.nl/emails")
            .bearer_auth(&self.api_key)
            .json(&payload)
            .send()
            .await?;

        if !res.status().is_success() {
            let err: Value = res.json().await?;
            return Err(err["error"].as_str().unwrap_or("Onbekende fout").into());
        }

        Ok(res.json().await?)
    }
}

// Gebruik:
// let ws = WesenderClient::new(std::env::var("WS_API_KEY")?);
// ws.send_email(json!({ "from": "...", "to": "...", ... })).await?;

Volgende stappen