sentd

Crates.iosentd
lib.rssentd
version1.0.0
created_at2026-01-25 15:30:50.811009+00
updated_at2026-01-25 15:30:50.811009+00
descriptionOfficial Rust SDK for the SENTD Email API
homepagehttps://sentd.io
repositoryhttps://github.com/sentd-it/sentd-rust
max_upload_size
id2068969
size85,602
(sentd-it)

documentation

https://docs.rs/sentd

README

SENTD Rust SDK

Official Rust client for the SENTD Email API.

Installation

Add this to your Cargo.toml:

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

Quick Start

use sentd::{Sentd, SendEmailRequest};

#[tokio::main]
async fn main() -> Result<(), sentd::Error> {
    // Create a new client
    let client = Sentd::new("your_api_key");

    // Send an email
    let result = client.emails().send(SendEmailRequest {
        from: "hello@yourdomain.com".to_string(),
        to: vec!["user@example.com".to_string()],
        subject: "Welcome!".to_string(),
        html: Some("<h1>Hello World</h1>".to_string()),
        ..Default::default()
    }).await?;

    println!("Email sent! ID: {}", result.data.id);
    Ok(())
}

Features

  • Emails - Send, list, get, cancel, reschedule, and resend emails
  • Batch - Send bulk emails efficiently
  • Templates - Create and manage email templates
  • Domains - Add and verify sending domains
  • Webhooks - Configure webhook endpoints
  • Analytics - Get email statistics

API Reference

Emails

// Send an email
let result = client.emails().send(SendEmailRequest {
    from: "hello@yourdomain.com".to_string(),
    to: vec!["user@example.com".to_string()],
    subject: "Hello".to_string(),
    html: Some("<h1>World</h1>".to_string()),
    ..Default::default()
}).await?;

// List emails
let emails = client.emails().list(Some(ListEmailsParams {
    limit: Some(10),
    status: Some("delivered".to_string()),
    ..Default::default()
})).await?;

// Get an email
let email = client.emails().get("email_id").await?;

// Cancel a scheduled email
client.emails().cancel("email_id").await?;

// Resend a failed email
client.emails().resend("email_id").await?;

Batch

use sentd::{SendBatchRequest, BatchEmail};
use std::collections::HashMap;

let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("Alice"));

let result = client.batch().send(SendBatchRequest {
    emails: vec![
        BatchEmail {
            to: "user1@example.com".to_string(),
            data: Some(data),
            ..Default::default()
        },
    ],
    from: Some("hello@yourdomain.com".to_string()),
    subject: Some("Newsletter".to_string()),
    html: Some("<h1>Hello {{name}}</h1>".to_string()),
    ..Default::default()
}).await?;

Templates

use sentd::CreateTemplateRequest;

// Create a template
let template = client.templates().create(CreateTemplateRequest {
    name: "Welcome Email".to_string(),
    subject_template: "Welcome, {{name}}!".to_string(),
    html_template: "<h1>Hello {{name}}</h1>".to_string(),
    ..Default::default()
}).await?;

// List templates
let templates = client.templates().list().await?;

// Preview a template
let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("John"));
let preview = client.templates().preview("template_id", data).await?;

Domains

// Add a domain
let domain = client.domains().add("yourdomain.com").await?;

// List domains
let domains = client.domains().list().await?;

// Verify a domain
let result = client.domains().verify("domain_id").await?;

Webhooks

use sentd::CreateWebhookRequest;

// Create a webhook
let webhook = client.webhooks().create(CreateWebhookRequest {
    url: "https://yourdomain.com/webhooks".to_string(),
    events: vec!["email.delivered".to_string(), "email.bounced".to_string()],
    active: Some(true),
}).await?;

// Test a webhook
let result = client.webhooks().test("webhook_id").await?;

Analytics

use sentd::analytics::AnalyticsParams;

// Get analytics
let analytics = client.analytics().get(Some(AnalyticsParams {
    days: Some(30),
    group_by: Some("day".to_string()),
})).await?;

// Export as CSV
let csv = client.analytics().export_csv(Some(30)).await?;

Configuration

// Custom base URL
let client = Sentd::with_base_url("your_api_key", "https://custom.api.sentd.io");

Error Handling

use sentd::Error;

match client.emails().send(request).await {
    Ok(result) => println!("Sent: {}", result.data.id),
    Err(Error::Authentication(msg)) => eprintln!("Invalid API key: {}", msg),
    Err(Error::RateLimit(msg)) => eprintln!("Rate limited: {}", msg),
    Err(Error::Validation(msg)) => eprintln!("Validation error: {}", msg),
    Err(Error::NotFound(msg)) => eprintln!("Not found: {}", msg),
    Err(e) => eprintln!("Error: {}", e),
}

License

MIT License - see LICENSE for details.

Commit count: 1

cargo fmt