Sdks
Rust SDK
Install and use the MisarMail Rust SDK
Installation
Add to Cargo.toml:
[dependencies]
misarmail = "0.1"
tokio = { version = "1", features = ["full"] }
Quick Start
use misarmail::{Client, types::{SendRequest, Address}};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(std::env::var("MISARMAIL_API_KEY")?);
let result = client
.send(SendRequest {
from: Address { email: "[email protected]".into(), name: Some("Misar".into()) },
to: vec![Address { email: "[email protected]".into(), name: None }],
subject: "Welcome".into(),
html: Some("<p>Hello from MisarMail!</p>".into()),
..Default::default()
})
.await?;
println!("Sent: {}", result.message_id);
Ok(())
}
Available Methods
| Method | Description |
|---|---|
client.send(req).await | Send a transactional email |
client.contacts().list(params).await | List contacts |
client.contacts().create(req).await | Create a contact |
client.contacts().get(id).await | Get a contact |
client.contacts().update(id, req).await | Update a contact |
client.contacts().delete(id).await | Delete a contact |
client.contacts().import_contacts(req).await | Bulk import/upsert contacts |
client.campaigns().list(params).await | List campaigns |
client.campaigns().create(req).await | Create a campaign |
client.campaigns().get(id).await | Get a campaign |
client.campaigns().update(id, req).await | Update a campaign |
client.campaigns().send(id).await | Send/schedule a campaign |
client.campaigns().delete(id).await | Delete a campaign |
client.templates().list(params).await | List templates |
client.templates().create(req).await | Create a template |
client.templates().get(id).await | Get a template |
client.templates().update(id, req).await | Update a template |
client.templates().delete(id).await | Delete a template |
client.templates().render(id, req).await | Render a template with merge data |
client.automations().list(params).await | List automations |
client.automations().create(req).await | Create an automation |
client.automations().get(id).await | Get an automation |
client.automations().update(id, req).await | Update an automation |
client.automations().delete(id).await | Delete an automation |
client.automations().activate(id).await | Activate/deactivate an automation |
client.domains().list().await | List sending domains |
client.domains().create(req).await | Add a sending domain |
client.domains().get(id).await | Get a domain |
client.domains().verify(id).await | Trigger domain DNS verification |
client.domains().delete(id).await | Delete a domain |
client.aliases().list(params).await | List email aliases |
client.aliases().create(req).await | Create an alias |
client.aliases().get(id).await | Get an alias |
client.aliases().update(id, req).await | Update an alias |
client.aliases().delete(id).await | Delete an alias |
client.dedicated_ips().list().await | List dedicated IPs |
client.dedicated_ips().create(req).await | Purchase a dedicated IP |
client.dedicated_ips().update(id, req).await | Update IP pool assignment |
client.dedicated_ips().delete(id).await | Release a dedicated IP |
client.ab_tests().list(params).await | List A/B tests |
client.ab_tests().create(req).await | Create an A/B test |
client.ab_tests().get(id).await | Get an A/B test |
client.ab_tests().set_winner(id, variant).await | Manually set the winning variant |
client.sandbox().send(req).await | Send in sandbox mode |
client.sandbox().list(params).await | List sandbox messages |
client.sandbox().delete(id).await | Delete a sandbox message |
client.inbound().list(params).await | List inbound routing rules |
client.inbound().create(req).await | Create an inbound route |
client.inbound().get(id).await | Get an inbound route |
client.inbound().delete(id).await | Delete an inbound route |
client.analytics().overview(params).await | Get send/open/click/bounce analytics |
client.track().event(req).await | Track a custom event |
client.track().purchase(req).await | Track a purchase event |
client.keys().list().await | List API keys |
client.keys().create(req).await | Create an API key |
client.keys().get(id).await | Get an API key |
client.keys().revoke(id).await | Revoke an API key |
client.validate().email(address).await | Validate an email address |
client.webhooks().list(params).await | List webhooks |
client.webhooks().create(req).await | Create a webhook endpoint |
client.webhooks().get(id).await | Get a webhook |
client.webhooks().update(id, req).await | Update a webhook |
client.webhooks().delete(id).await | Delete a webhook |
client.webhooks().test(id).await | Send a test event to a webhook |
client.usage().get(params).await | Get API usage stats |
client.billing().subscription().await | Get current subscription details |
client.billing().checkout(req).await | Create a billing checkout session |
client.workspaces().list().await | List workspaces |
client.workspaces().create(req).await | Create a workspace |
client.workspaces().get(id).await | Get a workspace |
client.workspaces().update(id, req).await | Update a workspace |
client.workspaces().delete(id).await | Delete a workspace |
client.workspaces().list_members(id).await | List workspace members |
client.workspaces().invite_member(id, req).await | Invite a member to workspace |
client.workspaces().update_member(id, user_id, req).await | Update member role |
client.workspaces().remove_member(id, user_id).await | Remove a member from workspace |
Examples
Webhooks
let wh = client.webhooks().create(CreateWebhookRequest {
url: "https://yourapp.com/webhooks/mail".into(),
events: vec!["email.delivered".into(), "email.opened".into()],
}).await?;
client.webhooks().test(&wh.id).await?;
Error Handling
use misarmail::Error;
match client.send(req).await {
Ok(r) => println!("Sent: {}", r.message_id),
Err(Error::Api { status, message }) => eprintln!("API {status}: {message}"),
Err(e) => eprintln!("Network error: {e}"),
}