| Crates.io | plunk |
| lib.rs | plunk |
| version | 0.1.2 |
| created_at | 2025-04-30 23:38:31.535302+00 |
| updated_at | 2025-05-01 00:19:17.019032+00 |
| description | A fast, simple, and easy-to-work-with Rust SDK for Plunk — send emails without the hassle. |
| homepage | |
| repository | https://github.com/yhoungdev/manifold/tree/main/crates/plunk |
| max_upload_size | |
| id | 1655586 |
| size | 50,867 |
# Plunk Email SDK
A simple Rust SDK for sending transactional emails using the Plunk API.
Cargo.toml:[dependencies]
reqwest = "0.12.15"
tokio = "1.44.2"
serde = "1.0.219"
common_manifold = "0.1.0"
dotenv = "0.15.0"
.env file with your credentials:PLUNK_PRIVATE_KEY=your_plunk_api_key_here
use plunk::prelude::{
PlunkClient,
PlunkClientTrait,
PlunkPayloads,
};
// Initialize the client
let plunk_key = env::var("PLUNK_PRIVATE_KEY").expect("Set PLUNK_PRIVATE_KEY in .env");
let client = PlunkClient::new(plunk_key);
// Create an email payload
let payload = PlunkPayloads {
to: "recipient@example.com".to_string(),
subject: Some("Hello! 👋".to_string()),
body: "Your email content here".to_string(),
};
// Send the email
match client.send_transactional_email(payload).await {
Ok(msg) => println!("{}", msg),
Err(err) => eprintln!("Error sending email: {}", err),
}
Initialize a new Plunk client:
let client = PlunkClient::new(plunk_key);
Structure for creating email payloads:
| Field | Type | Description |
|---|---|---|
| to | String | Recipient's email address |
| subject | Option |
Email subject (optional) |
| body | String | Email content (supports HTML) |
The send_transactional_email function returns a Result with either a success message or an error:
async fn send_transactional_email(payload: PlunkPayloads) -> Result<String, Error>
The SDK handles two main types of errors:
Always wrap the email sending operation in a proper error handling block:
match client.send_transactional_email(payload).await {
Ok(msg) => println!("Success: {}", msg),
Err(err) => eprintln!("Error: {}", err),
}
MIT