Skip to content

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

feat: Add skipped domains (#1293)

Amaury29119fa72027
diff --git a/core/src/smtp/error.rs b/core/src/smtp/error.rs
index 808b7afc..d0982d57 100644
--- a/core/src/smtp/error.rs
+++ b/core/src/smtp/error.rs
@@ -48,6 +48,8 @@ pub enum SmtpError {
HotmailError(HotmailError),
/// Error when verifying a Microsoft 365 email via HTTP request.
Microsoft365Error(Microsoft365Error),
+ /// Email is in the `skipped_domains` parameter.
+ SkippedDomain(String),
}
impl From<SocksError> for SmtpError {
diff --git a/core/src/smtp/mod.rs b/core/src/smtp/mod.rs
index 1bd11a01..36648fd1 100644
--- a/core/src/smtp/mod.rs
+++ b/core/src/smtp/mod.rs
@@ -57,6 +57,17 @@ pub async fn check_smtp(
input: &CheckEmailInput,
) -> Result<SmtpDetails, SmtpError> {
let host_lowercase = host.to_lowercase().to_string();
+
+ if input
+ .skipped_domains
+ .iter()
+ .any(|d| host_lowercase.contains(d))
+ {
+ return Err(SmtpError::SkippedDomain(format!(
+ "Reacher currently cannot verify emails from @{domain}"
+ )));
+ }
+
// FIXME Is this `contains` too lenient?
if input.yahoo_use_api && host_lowercase.contains("yahoo") {
return yahoo::check_yahoo(to_email, input)
@@ -129,4 +140,19 @@ mod tests {
_ => panic!("check_smtp did not time out"),
}
}
+
+ #[test]
+ fn should_skip_domains() {
+ let runtime = Runtime::new().unwrap();
+
+ let to_email = EmailAddress::from_str("[email protected]").unwrap();
+ let host = Name::from_str("mx01.mail.icloud.com.").unwrap();
+ let input = CheckEmailInput::default();
+
+ let res = runtime.block_on(check_smtp(&to_email, &host, 25, "icloud.com", &input));
+ match res {
+ Err(SmtpError::SkippedDomain(_)) => (),
+ r => panic!("{:?}", r),
+ }
+ }
}
diff --git a/core/src/util/input_output.rs b/core/src/util/input_output.rs
index 79ecc781..71b883d7 100644
--- a/core/src/util/input_output.rs
+++ b/core/src/util/input_output.rs
@@ -137,6 +137,25 @@ pub struct CheckEmailInput {
///
/// Defaults to Opportunistic.
pub smtp_security: SmtpSecurity,
+ /// **IMPORTANT:** This is a beta feature, and might be completely removed,
+ /// or moved somewhere else, before the next release.
+ ///
+ /// List of domains to skip when doing an SMTP connection, because we know
+ /// they return "unknown". For each string in this list, we check if the MX
+ /// record **contains** the string; if yes, we return an error saying the
+ /// SMTP verification is skipped.
+ ///
+ /// Related issue: https://github.com/reacherhq/check-if-email-exists/issues/937
+ ///
+ /// ## Example
+ ///
+ /// If you want to skip Zoho emails, it's good enough to ".zoho.com." to
+ /// the list. This way it will skip all Zoho emails as their MX records
+ /// show "mx{N}.zoho.com.". Simply putting "zoho" might give false
+ /// positives if you have an email provider like "mycustomzoho.com".
+ ///
+ /// Defaults to: [""]
+ pub skipped_domains: Vec<String>,
}
impl Default for CheckEmailInput {
@@ -157,6 +176,21 @@ impl Default for CheckEmailInput {
check_gravatar: false,
haveibeenpwned_api_key: None,
retries: 2,
+ skipped_domains: vec![
+ // on @bluewin.ch
+ // - mx-v02.bluewin.ch.
+ ".bluewin.ch.".into(),
+ // on @bluewin.ch
+ // - mxbw-bluewin-ch.hdb-cs04.ellb.ch.
+ "bluewin-ch.".into(),
+ // on @gmx.de, @gmx.ch, @gmx.net
+ ".gmx.net.".into(),
+ // on @icloud.com
+ ".mail.icloud.com.".into(),
+ // on @web.de
+ ".web.de.".into(),
+ ".zoho.com.".into(),
+ ],
}
}
}
@@ -305,6 +339,16 @@ impl CheckEmailInput {
self.hotmail_use_headless = use_headless;
self
}
+
+ /// **IMPORTANT:** This is a beta feature, and might be completely removed,
+ /// or moved somewhere else, before the next release.
+ ///
+ /// List of domains to skip when doing an SMTP connection, because we know
+ /// they return "unknown".
+ pub fn set_skipped_domains(&mut self, domains: Vec<String>) -> &mut CheckEmailInput {
+ self.skipped_domains = domains;
+ self
+ }
}
/// An enum to describe how confident we are that the recipient address is