Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

Use tabs

Amaury Martiny00d3de4130b5
diff --git a/src/main.rs b/src/main.rs
index c36a950c..58490fb6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,42 +16,42 @@ mod mx_hosts;
mod with_lettre;
fn main() {
- env_logger::init();
-
- // The YAML file is found relative to the current file, similar to how modules are found
- let yaml = load_yaml!("cli.yml");
- let matches = App::from_yaml(yaml).get_matches();
-
- let from_email = matches.value_of("from").unwrap_or("[email protected]");
- // Calling .unwrap() is safe here because "TO" is required
- let to_email = matches.value_of("TO").unwrap();
-
- info!("User inputted email '{}'", to_email);
-
- let domain = match to_email.split("@").skip(1).next() {
- Some(i) => i,
- None => {
- error!("'{}' is not a valid email.", to_email);
- process::exit(1);
- }
- };
- debug!("Domain name is '{}'", domain);
-
- debug!("Getting MX lookup...");
- let hosts = mx_hosts::get_mx_lookup(domain);
- info!("Found the following MX hosts {:?}", hosts);
- let ports = vec![SMTP_PORT, SUBMISSION_PORT, 465];
- let mut combinations = Vec::new(); // `(host, port)` combination
- for port in ports.into_iter() {
- for host in hosts.iter() {
- combinations.push((host.exchange(), port))
- }
- }
-
- let found = combinations
- .par_iter() // Parallelize the find_any
- .find_any(|(host, port)| with_lettre::email_exists(from_email, to_email, host, *port))
- .is_some();
-
- println!("{}", found);
+ env_logger::init();
+
+ // The YAML file is found relative to the current file, similar to how modules are found
+ let yaml = load_yaml!("cli.yml");
+ let matches = App::from_yaml(yaml).get_matches();
+
+ let from_email = matches.value_of("from").unwrap_or("[email protected]");
+ // Calling .unwrap() is safe here because "TO" is required
+ let to_email = matches.value_of("TO").unwrap();
+
+ info!("User inputted email '{}'", to_email);
+
+ let domain = match to_email.split("@").skip(1).next() {
+ Some(i) => i,
+ None => {
+ error!("'{}' is not a valid email.", to_email);
+ process::exit(1);
+ }
+ };
+ debug!("Domain name is '{}'", domain);
+
+ debug!("Getting MX lookup...");
+ let hosts = mx_hosts::get_mx_lookup(domain);
+ info!("Found the following MX hosts {:?}", hosts);
+ let ports = vec![SMTP_PORT, SUBMISSION_PORT, 465];
+ let mut combinations = Vec::new(); // `(host, port)` combination
+ for port in ports.into_iter() {
+ for host in hosts.iter() {
+ combinations.push((host.exchange(), port))
+ }
+ }
+
+ let found = combinations
+ .par_iter() // Parallelize the find_any
+ .find_any(|(host, port)| with_lettre::email_exists(from_email, to_email, host, *port))
+ .is_some();
+
+ println!("{}", found);
}
diff --git a/src/mx_hosts.rs b/src/mx_hosts.rs
index 84540493..0082c4c5 100644
--- a/src/mx_hosts.rs
+++ b/src/mx_hosts.rs
@@ -5,11 +5,11 @@ use self::trust_dns_resolver::lookup::MxLookup;
use self::trust_dns_resolver::Resolver;
pub fn get_mx_lookup(domain: &str) -> MxLookup {
- // Construct a new Resolver with default configuration options
- let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();
+ // Construct a new Resolver with default configuration options
+ let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();
- // Lookup the MX records associated with a name.
- // The final dot forces this to be an FQDN, otherwise the search rules as specified
- // in `ResolverOpts` will take effect. FQDN's are generally cheaper queries.
- resolver.mx_lookup(domain).unwrap()
+ // Lookup the MX records associated with a name.
+ // The final dot forces this to be an FQDN, otherwise the search rules as specified
+ // in `ResolverOpts` will take effect. FQDN's are generally cheaper queries.
+ resolver.mx_lookup(domain).unwrap()
}