Skip to content

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

fix(mx): Detect Microsoft consumer domains on mx.microsoft hosts as Hotmail B2C (#1669)

Amauryf5282bcc9a62
diff --git a/core/src/mx/mod.rs b/core/src/mx/mod.rs
index 978da73d..6ad159ac 100644
--- a/core/src/mx/mod.rs
+++ b/core/src/mx/mod.rs
@@ -103,7 +103,6 @@ pub fn is_gmail(mx_host: &str) -> bool {
/// Check if a MX host is from outlook (includes @hotmail.*, @outlook.* and
/// all Microsoft 365 addresses).
///
-/// After some testing I got:
/// After some testing, I got:
/// - *@outlook.com -> `outlook-com.olc.protection.outlook.com.`
/// - *@outlook.fr -> `eur.olc.protection.outlook.com.`
@@ -113,21 +112,54 @@ pub fn is_gmail(mx_host: &str) -> bool {
///
/// But Microsoft 365 (B2B) addresses end with "mail.protection.outlook.com."
///
+/// Microsoft is also migrating domains to MX hosts under "mx.microsoft.",
+/// both for consumer domains and Microsoft 365 tenants:
+/// - *@outlook.cz -> `outlook-cz.d-v1.mx.microsoft.`
+/// - *@hotmail.cz -> `hotmail-cz.f-v1.mx.microsoft.`
+/// - *@contoso.com -> `contoso-com.a-v1.mx.microsoft.`
+///
/// TL;DR:
-/// - B2C emails -> end with ".olc.protection.outlook.com."
-/// - B2B emails -> end with ".mail.protection.outlook.com."
+/// - B2C emails -> end with ".olc.protection.outlook.com.", or a consumer
+/// domain under ".mx.microsoft." (see `is_hotmail_b2c`)
+/// - B2B emails -> everything else
pub fn is_hotmail(mx_host: &str) -> bool {
- mx_host.to_lowercase().ends_with(".protection.outlook.com.")
+ let host = mx_host.to_lowercase();
+ host.ends_with(".protection.outlook.com.") || host.ends_with(".mx.microsoft.")
}
/// Check if an address is a Hotmail B2B email address.
pub fn is_hotmail_b2b(mx_host: &str) -> bool {
- is_hotmail(mx_host) && !mx_host.ends_with(".olc.protection.outlook.com.")
+ is_hotmail(mx_host) && !is_hotmail_b2c(mx_host)
}
/// Check if an address is a Hotmail B2C email address.
pub fn is_hotmail_b2c(mx_host: &str) -> bool {
- is_hotmail(mx_host) && mx_host.ends_with(".olc.protection.outlook.com.")
+ let host = mx_host.to_lowercase();
+ if host.ends_with(".olc.protection.outlook.com.") {
+ return true;
+ }
+
+ // On "mx.microsoft.", consumer and Microsoft 365 domains share the same
+ // MX format, with the first label being the domain with dots replaced by
+ // dashes. We consider it B2C if that label looks like a Microsoft consumer
+ // domain, i.e. a consumer brand followed by a TLD (e.g. "outlook-cz" or
+ // "hotmail-co-uk").
+ let Some(rest) = host.strip_suffix(".mx.microsoft.") else {
+ return false;
+ };
+ let label = rest.split('.').next().unwrap_or_default();
+ let mut parts = label.split('-');
+ let is_consumer_brand = matches!(
+ parts.next(),
+ Some("hotmail" | "outlook" | "live" | "msn" | "windowslive")
+ );
+ let tld_parts: Vec<&str> = parts.collect();
+
+ is_consumer_brand
+ && !tld_parts.is_empty()
+ && tld_parts
+ .iter()
+ .all(|p| (2..=3).contains(&p.len()) && p.chars().all(|c| c.is_ascii_alphabetic()))
}
/// Check if the MX host is behind Mimecast.
@@ -158,4 +190,44 @@ mod tests {
assert!(is_proofpoint("mx1.PPHOSTED.COM."));
assert!(is_proofpoint("mx2.ppe-hosted.com."));
}
+
+ #[test]
+ fn hotmail_b2c_detection() {
+ for host in [
+ "outlook-com.olc.protection.outlook.com.",
+ "eur.olc.protection.outlook.com.",
+ // https://github.com/reacherhq/check-if-email-exists/issues/1663
+ "outlook-cz.d-v1.mx.microsoft.",
+ "hotmail-cz.f-v1.mx.microsoft.",
+ "HOTMAIL-CO-UK.a-v1.mx.microsoft.",
+ "live-com.b-v1.mx.microsoft.",
+ ] {
+ assert!(is_hotmail(host), "{}", host);
+ assert!(is_hotmail_b2c(host), "{}", host);
+ assert!(!is_hotmail_b2b(host), "{}", host);
+ }
+ }
+
+ #[test]
+ fn hotmail_b2b_detection() {
+ for host in [
+ "contoso-com.mail.protection.outlook.com.",
+ "contoso-com.a-v1.mx.microsoft.",
+ "outlook-tips-blog.a-v1.mx.microsoft.",
+ "hotmail.a-v1.mx.microsoft.",
+ ] {
+ assert!(is_hotmail(host), "{}", host);
+ assert!(!is_hotmail_b2c(host), "{}", host);
+ assert!(is_hotmail_b2b(host), "{}", host);
+ }
+ }
+
+ #[test]
+ fn non_microsoft_hosts() {
+ for host in ["gmail-smtp-in.l.google.com.", "mx.microsoft.example.com."] {
+ assert!(!is_hotmail(host), "{}", host);
+ assert!(!is_hotmail_b2c(host), "{}", host);
+ assert!(!is_hotmail_b2b(host), "{}", host);
+ }
+ }
}