How to Validate Email Address in Rust

Check if an email address is correct and really exists using the Rust lang and Real Email 🦀

Email Validation in a Nutshell

An Email Address can look right but still be wrong and bounce. MailValidation.io uses in depth email address validation to check if emails really exist without sending any messages.

Email Validation Using an API Key

With an API key you wont be limited by how many addresses you can check or how fast you can check them. In Rust the example changes to add the API key.

				
					use serde::{Deserialize};
use reqwest::Error;

#[derive(Deserialize, Debug)]
struct Response {
    status: String
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    let email = "foo@bar.com";
    let api_key = ???;
    let team_slug = ???;
    let mut map = HashMap::new();
    map.insert("email", email);
    
    let request_url = format!("https://app.mailvalidation.io/a/{team_slug}/validate/api/validate/",
                              team_slug = team_slug);
    let result: Response = reqwest::get(&request_url)
        .json(&map)
        .header("Authorization", "Api-Key ".&api_key
        .send().await?.json().await?;

    println!("{:?}", result.status);

    Ok(())
}
				
			

Support

Are you having trouble, have some questions. How can we help?