Skip to main content

Crate mailtrap

Crate mailtrap 

Source
Expand description

§Mailtrap

mailtrap is an unofficial Rust library for interacting with the Mailtrap API. It allows you to create and send emails programmatically.

§Usage

Add this to your Cargo.toml:

[dependencies]
mailtrap = "0.1.0"
tokio = { version = "1", features = ["full"] }

§Example

use mailtrap::Email;

#[tokio::main]
async fn main() {
    let email = Email::new()
        .from("sender@example.com")
        .to("recipient@example.com")
        .subject("Hello from Rust")
        .text("This is a test email sent from Rust using the Mailtrap API.")
        .category("test");

    // send returns a Result<bool, Error>
    // You need to provide the API endpoint and your API token.
    let res = email.send(
        Some("https://send.api.mailtrap.io/"),
        Some("YOUR_API_TOKEN"),
        None
    ).await;

    match res {
        Ok(success) => {
            if success {
                println!("Email sent successfully!");
            } else {
                println!("Failed to send email.");
            }
        }
        Err(e) => eprintln!("Error: {}", e),
    }
}

Re-exports§

pub use email::*;
pub use access::*;

Modules§

access
email