Skip to content

lettermint/lettermint-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lettermint Rust SDK

Crates.io Version Crates.io Downloads docs.rs GitHub Tests Dependency Status License Join our Discord server

Official Rust SDK for the Lettermint sending and team APIs.

Requirements

  • Current stable Rust. The crate's rust-version tracks the current supported stable minor release.
  • Tokio or another async runtime compatible with reqwest

Installation

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

Send Email

use lettermint::Lettermint;

#[tokio::main]
async fn main() -> lettermint::Result<()> {
    let email = Lettermint::email(std::env::var("LETTERMINT_TOKEN").unwrap())?;

    let response = email
        .email()
        .from("sender@example.com")
        .to("recipient@example.com")
        .subject("Hello from Rust")
        .html("<p>Hello from Lettermint.</p>")
        .idempotency_key("welcome-123")
        .send()
        .await?;

    println!("{}", response.message_id);
    Ok(())
}

The fluent email builder owns its payload. Each call to email.email() starts with a fresh payload, so attachments, headers, metadata, and recipients do not leak between sends.

Direct API Payloads

use lettermint::{types, Lettermint};

#[tokio::main]
async fn main() -> lettermint::Result<()> {
    let email = Lettermint::email(std::env::var("LETTERMINT_TOKEN").unwrap())?;

    let payload = types::SendMailRequest {
        from: "sender@example.com".into(),
        to: vec!["recipient@example.com".into()],
        subject: "Typed payload".into(),
        text: Some("Hello from Lettermint.".into()),
        ..Default::default()
    };

    email.send(&payload).await?;
    Ok(())
}

Team API

use lettermint::Lettermint;

#[tokio::main]
async fn main() -> lettermint::Result<()> {
    let api = Lettermint::api(std::env::var("LETTERMINT_TEAM_TOKEN").unwrap())?;
    let domains = api.domains().list(&[("page[size]", "10")]).await?;

    for domain in domains.data {
        println!("{}", domain.domain);
    }

    Ok(())
}

Lettermint::email(...) authenticates with X-Lettermint-Token for sending endpoints. Lettermint::api(...) authenticates with Authorization: Bearer ... for team endpoints.

Webhooks

use lettermint::Webhook;

fn handle(payload: &str, signature: &str, delivery: i64) -> lettermint::Result<serde_json::Value> {
    Webhook::new(std::env::var("LETTERMINT_WEBHOOK_SECRET").unwrap())
        .verify(payload, signature, Some(delivery))
}

Webhook verification checks the t=... timestamp, validates the v1=... HMAC-SHA256 signature in constant time, cross-checks the optional delivery timestamp, and enforces a 5 minute tolerance by default.

Development

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features --locked

Generated DTOs live in src/types.rs. Regenerate them from the repository root with:

python3 sdk-generator/rust/generate-types.py

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages