Rust SDK
Rust 1.70+
Cargo
Send emails with Rust using the official Laneful Rust SDK. Built for performance and safety with async support.
Full Feature Support
Templates, attachments, tracking, webhooks
Async/Await
Built on tokio for async operations
TLS Options
rustls (default) or native-tls
On this page
Prerequisites
To get the most out of this guide, you'll need:
- • Rust 1.70 or higher
- • Cargo package manager
- • A Laneful account with API key
- • Verified domain for sending emails
Installation
Using Cargo
Add the Laneful Rust SDK to your project:
cargo add laneful-rs
Or add to Cargo.toml
laneful-rs = "0.1"
Async API
Enable async support with the async feature:
laneful-rs = { version = "0.1", features = ["async"] }TLS Backend
The SDK uses rustls by default. To use native-tls instead:
laneful-rs = { version = "0.1", features = ["native-tls"] }Quick Start
Send your first email in minutes:
Send Simple Text Email
use laneful_rs::{Email, LanefulClient};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client
let client = LanefulClient::new(
"https://your-endpoint.send.laneful.net",
"your-auth-token",
)?;
// Create email
let email = Email::builder()
.from("sender@example.com", Some("Your Name"))
.to("recipient@example.com", Some("Recipient Name"))
.subject("Hello from Laneful!")
.text_content("This is a simple test email sent using the Laneful Rust SDK.")
.build()?;
// Send email
let response = client.send_one(email)?;
println!("✓ Email sent successfully! Status: {:?}", response);
Ok(())
}Examples
Common use cases and patterns:
Async Email Sending
use laneful_rs::{Email, LanefulClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = LanefulClient::new(
"https://your-endpoint.send.laneful.net",
"your-auth-token",
)?;
let email = Email::builder()
.from("sender@example.com", Some("Sender"))
.to("recipient@example.com", Some("Recipient"))
.subject("Hello from Laneful (async)!")
.text_content("This is a test email.")
.build()?;
let response = client.send_one_async(email).await?;
println!("Sent: {:?}", response);
Ok(())
}HTML Email with Tracking
use laneful_rs::{Email, Tracking};
let email = Email::builder()
.from("sender@example.com", Some("Your Name"))
.to("recipient@example.com", Some("Recipient Name"))
.subject("HTML Email with Tracking")
.html_content("<h1>Welcome!</h1><p>This is an <strong>HTML email</strong> with tracking.</p>")
.text_content("Welcome! This is an HTML email with tracking enabled.")
.tracking(Tracking { opens: true, clicks: true })
.tag("welcome-email")
.build()?;
let response = client.send_one(email)?;Template Email
use serde_json::json;
let email = Email::builder()
.from("sender@example.com", None)
.to("user@example.com", None)
.subject("Welcome to Acme!")
.template_id("welcome-template")
.template_data(json!({
"name": "John Doe",
"company": "Acme Corporation",
"activation_link": "https://example.com/activate"
}))
.build()?;
let response = client.send_one(email)?;Email with Attachments
use std::fs;
use base64::Engine;
use laneful_rs::Attachment;
// Read file and encode as base64
let file_data = fs::read("/path/to/document.pdf")?;
let content = base64::engine::general_purpose::STANDARD.encode(&file_data);
let email = Email::builder()
.from("sender@example.com", None)
.to("user@example.com", None)
.subject("Document Attached")
.text_content("Please find the document attached.")
.attachment(Attachment {
filename: "document.pdf".to_string(),
content,
content_type: "application/pdf".to_string(),
})
.build()?;
let response = client.send_one(email)?;Multiple Recipients with Reply-To
let email = Email::builder()
.from("sender@example.com", Some("Your Name"))
.to("user1@example.com", Some("User One"))
.to("user2@example.com", Some("User Two"))
.cc("cc@example.com", Some("CC Recipient"))
.bcc("bcc@example.com", Some("BCC Recipient"))
.reply_to("reply@example.com", Some("Reply To"))
.subject("Email to Multiple Recipients")
.text_content("This email is being sent to multiple recipients.")
.build()?;
let response = client.send_one(email)?;Scheduled Email
use std::time::{SystemTime, UNIX_EPOCH};
// Schedule for 24 hours from now
let send_time = SystemTime::now()
.duration_since(UNIX_EPOCH)?
.as_secs() + (24 * 60 * 60);
let email = Email::builder()
.from("sender@example.com", None)
.to("user@example.com", None)
.subject("Scheduled Email")
.text_content("This email was scheduled.")
.send_time(send_time)
.build()?;
let response = client.send_one(email)?;Batch Email Sending
let emails = vec![
Email::builder()
.from("sender@example.com", None)
.to("user1@example.com", None)
.subject("Email 1")
.text_content("First email content.")
.build()?,
Email::builder()
.from("sender@example.com", None)
.to("user2@example.com", None)
.subject("Email 2")
.text_content("Second email content.")
.build()?,
];
let response = client.send_batch(emails)?;Ready to Get Started?
Start sending emails with Rust in minutes. Check out the examples and integrate with your application.