Rust

This page provides an example of how to send an email using the NotifiedBy API in Rust.

use reqwest::Client;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let url = "https://api.notifiedby.com/v1/email/send/";

    let mut params = HashMap::new();
    params.insert("recipient", "YOU@TESTEMAIL");
    params.insert("subject", "email from API");
    params.insert("body", "<h1>Email from API</h1><p>This is an <strong>HTML</strong> email body.</p>");
    params.insert("plain_body", "This is the plain text version of the email body.");

    let response = client.post(url)
        .header("Authorization", "Api-Key YOUR_API_KEY")
        .form(&params)
        .send()
        .await?;

    let response_text = response.text().await?;
    println!("{}", response_text);


    Ok(())
}

Example with Encryption Key

use reqwest::Client;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let url = "https://api.notifiedby.com/v1/email/send/";

    let mut params = HashMap::new();
    params.insert("recipient", "YOU@TESTEMAIL");
    params.insert("subject", "email from API");
    params.insert("body", "<h1>Email from API</h1><p>This is an <strong>HTML</strong> email body.</p>");
    params.insert("plain_body", "This is the plain text version of the email body.");

    let response = client.post(url)
        .header("Authorization", "Api-Key YOUR_API_KEY")
        .header("Encryption-Key", "my-encryption-key")
        .form(&params)
        .send()
        .await?;

    let response_text = response.text().await?;
    println!("{}", response_text);

    Ok(())
}

Make sure to add reqwest and tokio to your Cargo.toml file

[dependencies]
reqwest = { version = "0.11", features = ["blocking"] }
tokio = { version = "1", features = ["full"] }