Get started sending emails with the Lettr Rust SDK
Send transactional emails from your Rust applications using the official Lettr Rust SDK. The SDK provides a type-safe, async-first interface for the Lettr API with full Tokio support and zero-copy deserialization.Using Cursor? Jump straight in using this prompt
Get started in three quick steps: install, configure, and send.
1
Install the SDK
cargo add lettrcargo add tokio --features macros,rt-multi-thread
The SDK requires Tokio as an async runtime. The macros feature provides #[tokio::main] and the rt-multi-thread feature enables the multi-threaded runtime.
2
Create a client
use lettr::Lettr;#[tokio::main]async fn main() -> lettr::Result<()> { let client = Lettr::new("your-api-key"); // Verify the client is configured correctly let auth = client.auth_check().await?; println!("Connected to Lettr (Team ID: {})", auth.data.team_id); Ok(())}
Store your API key in environment variables, never hardcode it. API keys use the lttr_ prefix followed by 64 hexadecimal characters.
3
Send your first email
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>Hello!</h1><p>This is a test email.</p>"); let response = client.emails.send(email).await?; println!("Email sent! Request ID: {}, Accepted: {}", response.request_id, response.accepted); Ok(())}
The response includes a request_id for tracking and the number of accepted recipients.
The sender domain must be verified in your Lettr dashboard before you can send emails. Sending from an unverified domain returns a validation error.
let email = CreateEmailOptions::new( "[email protected]", ["[email protected]"], "Plain text email",).with_text("This is a plain text email.\n\nIt has no HTML formatting.");client.emails.send(email).await?;
Send both HTML and plain text versions for maximum compatibility:
let email = CreateEmailOptions::new( "[email protected]", ["[email protected]"], "Multipart email",).with_html("<h1>Hello!</h1><p>This is the HTML version.</p>").with_text("Hello!\n\nThis is the plain text version.");client.emails.send(email).await?;
Providing both HTML and plain text ensures your emails are readable in all email clients, including text-only clients and accessibility tools.