Skip to content

lettr-com/lettr-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lettr

Official Rust SDK for the Lettr Email API. An async, typed client for emails, templates, domains, webhooks, audience, and campaigns.

Crates.io Documentation MIT License

Installation

Add lettr to your Cargo.toml:

[dependencies]
lettr = "1.3"

Or with the Cargo CLI:

cargo add lettr

Quick Start

use lettr::{Lettr, CreateEmailOptions};

#[tokio::main]
async fn main() -> lettr::Result<()> {
    let client = Lettr::new("your-api-key");

    let email = CreateEmailOptions::new(
        "[email protected]",
        ["[email protected]"],
        "Hello from Lettr!",
    )
    .with_html("<h1>Welcome!</h1>");

    let response = client.emails.send(email).await?;
    println!("Email sent! Request ID: {}", response.request_id);

    Ok(())
}

Lettr::from_env() reads the key from LETTR_API_KEY instead.

Error Handling

Methods return lettr::Result<T> with a unified Error you can match on:

# use lettr::{Lettr, CreateEmailOptions, Error};
# async fn run() {
# let client = Lettr::new("key");
# let email = CreateEmailOptions::new("[email protected]", ["[email protected]"], "Hi");
match client.emails.send(email).await {
    Ok(response) => println!("Sent! ID: {}", response.request_id),
    Err(Error::Validation(e)) => eprintln!("Validation: {} {:?}", e.message, e.errors),
    Err(Error::Api(e)) => eprintln!("API error: {} ({:?})", e.message, e.error_code),
    Err(e) => eprintln!("Error: {e}"),
}
# }

See Error Handling for the full set of variants.

Feature Flags

Feature Default Description
native-tls Yes Use the system's native TLS stack
rustls-tls No Use rustls for TLS
blocking No Enable the synchronous (blocking) API

With blocking, drop the .await — methods return Result directly.

Documentation

Full guides for every service, with complete request/response details, live in the docs:

📚 docs.lettr.com/quickstart/rust

Topic Guide
Install, client, sending Quickstart
Async patterns, batch sending, error handling Advanced
Manage Lettr templates & merge tags Templates
Add, verify, and manage sending domains Domains
Webhook endpoints for delivery & engagement events Webhooks
Lists, contacts, topics, properties, segments Audience
List, send, and schedule campaigns Campaigns
Endpoint reference (params & schemas) API Reference

License

MIT

Packages

 
 
 

Contributors

Languages