Advertisement
Guest User

mail.tm api

a guest
Jun 22nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.98 KB | None | 0 0
  1. use json;
  2. use rand::distributions::Alphanumeric;
  3. use rand::{thread_rng, Rng};
  4. use reqwest;
  5. use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE};
  6. use std::thread;
  7. use std::time::Duration;
  8. use std::{collections::HashMap, io, iter, vec::Vec};
  9.  
  10. fn gen_address() -> Vec<String> {
  11.     let mut rng = thread_rng();
  12.     let address: String = iter::repeat(())
  13.         .map(|()| rng.sample(Alphanumeric))
  14.         .map(char::from)
  15.         .take(10)
  16.         .collect();
  17.  
  18.     let password: String = iter::repeat(())
  19.         .map(|()| rng.sample(Alphanumeric))
  20.         .map(char::from)
  21.         .take(5)
  22.         .collect();
  23.     let body = reqwest::blocking::get("https://api.mail.tm/domains")
  24.         .unwrap()
  25.         .text()
  26.         .unwrap();
  27.     let domains = json::parse(&body).expect("Failed to parse domain json.");
  28.  
  29.     let domain = domains["hydra:member"][0]["domain"].to_string();
  30.     let email = format!("{}@{}", &address, &domain);
  31.     vec![email, password]
  32. }
  33.  
  34. fn gen_email() -> Vec<String> {
  35.     let client = reqwest::blocking::Client::new();
  36.     let address_info = gen_address();
  37.     let address = &address_info[0];
  38.     let password = &address_info[1];
  39.  
  40.     let mut data = HashMap::new();
  41.     data.insert("address", &address);
  42.     data.insert("password", &password);
  43.  
  44.     let mut headers = HeaderMap::new();
  45.     headers.insert(ACCEPT, HeaderValue::from_static("application/ld+json"));
  46.     headers.insert(
  47.         CONTENT_TYPE,
  48.         HeaderValue::from_static("application/ld+json"),
  49.     );
  50.  
  51.     let res = client
  52.         .post("https://api.mail.tm/accounts")
  53.         .headers(headers)
  54.         .json(&data)
  55.         .send()
  56.         .expect("Error while attempting to create acconut.");
  57.  
  58.     vec![
  59.         res.status().to_string(),
  60.         address.to_string(),
  61.         password.to_string(),
  62.     ]
  63. }
  64.  
  65. fn main() {
  66.     fn get_amount() -> i32 {
  67.         let mut amount = String::new();
  68.  
  69.         loop {
  70.             println!("How many emails do you want?");
  71.             io::stdin()
  72.                 .read_line(&mut amount)
  73.                 .expect("Failed to read line.");
  74.  
  75.             let _amount: i32 = match amount.trim().parse() {
  76.                 Ok(num) => return num,
  77.                 Err(_) => {
  78.                     println!("Please enter a number.");
  79.                     continue;
  80.                 }
  81.             };
  82.         }
  83.     }
  84.  
  85.     let amount = get_amount();
  86.     let handle = thread::spawn(move || {
  87.         let mut handles = vec![];
  88.         for _gen in 0..amount {
  89.             thread::sleep(Duration::from_secs_f32(0.5));
  90.             let handle = thread::spawn(|| {
  91.                 let maildata = gen_email();
  92.                 println!(
  93.                     "Status: {}, Address: {}, Password: {}",
  94.                     maildata[0], maildata[1], maildata[2]
  95.                 );
  96.             });
  97.             handles.push(handle);
  98.         }
  99.         handles.into_iter().for_each(|h| h.join().unwrap());
  100.     });
  101.     handle.join().unwrap();
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement