Skip to content

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

fix: Rename valid_format to is_valid_syntax (#288)

Amaury Martinyeae64821c31d
diff --git a/README.md b/README.md
index 7d784a0a..b711e238 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,6 @@
[![Crate](https://img.shields.io/crates/v/check-if-email-exists.svg)](https://crates.io/crates/check-if-email-exists)
[![Docs](https://docs.rs/check-if-email-exists/badge.svg)](https://docs.rs/check-if-email-exists)
+[![Actions Status](https://github.com/amaurymartiny/check-if-email-exists/workflows/pr/badge.svg)](https://github.com/amaurymartiny/check-if-email-exists/actions)
[![Travis](https://img.shields.io/travis/amaurymartiny/check-if-email-exists.svg)](https://travis-ci.org/amaurymartiny/check-if-email-exists)
[![Appveyor](https://ci.appveyor.com/api/projects/status/github/amaurymartiny/check-if-email-exists?branch=master&svg=true)](https://ci.appveyor.com/project/amaurymartiny/check-if-email-exists-a08kp)
![License](https://img.shields.io/github/license/amaurymartiny/check-if-email-exists.svg)
@@ -15,35 +16,23 @@
This software is licensed under the GPL-3.0 license, which forbids it being integrated and distributed in closed-source commercials projects. [Message me](mailto:[email protected]) if you wish an alternate licensing.
-## ✅ What Does This Tool Check?
-
-The main feature this tool checks is:
-
-✅ **Email deliverability:** Is an email for this address deliverable?
-
-However, it goes more into details, and checks all the following properties of an email address:
-
-✔️ **Syntax validation.** Is the address syntactically valid?
-
-✔️ **DNS records validation.** Does the domain of the email address have valid MX DNS records?
-
-✔️ **Disposable email address (DEA) validation.** Is the address provided by a known [disposable email address](https://en.wikipedia.org/wiki/Disposable_email_address) provider?
-
-✔️ **SMTP server validation.** Can the mail exchanger of the email address domain be contacted successfully?
-
-✔️ **Mailbox disabled.** Has this email address been disabled by the email provider?
-
-✔️ **Full inbox.** Is the inbox of this mailbox full?
-
-✔️ **Catch-all address.** Is this email address a [catch-all](https://debounce.io/blog/help/what-is-a-catch-all-or-accept-all/) address?
-
-Planned features:
-
-- [ ] **Role account validation.** Is the email address a well-known role account?
-- [ ] **Free email provider check.** Is the email address bound to a known free email provider?
-- [ ] **Syntax validation, provider-specific.** According to the syntactic rules of the target mail provider, is the address syntactically valid?
-- [ ] **Honeypot detection.** Does email address under test hide a [honeypot](https://en.wikipedia.org/wiki/Spamtrap)?
-- [ ] **Gravatar.** Does this email address have a [Gravatar](https://gravatar.com/) profile picture?
+## What Does This Tool Check?
+
+| Included? | Feature | Description | JSON field |
+| --------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
+| ✅ | **Email deliverability** | Is an email sent to this address deliverable? | `smtp.is_deliverable` |
+| ✅ | **Syntax validation** | Is the address syntactically valid? | `syntax.is_valid_syntax` |
+| ✅ | **DNS records validation** | Does the domain of the email address have valid MX DNS records? | `mx.records` |
+| ✅ | **Disposable email address (DEA) validation** | Is the address provided by a known [disposable email address](https://en.wikipedia.org/wiki/Disposable_email_address) provider? | `misc.is_disposable` |
+| ✅ | **SMTP server validation** | Can the mail exchanger of the email address domain be contacted successfully? | `smtp.*` |
+| ✅ | **Mailbox disabled** | Has this email address been disabled by the email provider? | `smtp.is_disabled` |
+| ✅ | **Full inbox** | Is the inbox of this mailbox full? | `smtp.has_full_inbox` |
+| ✅ | **Catch-all address** | Is this email address a [catch-all](https://debounce.io/blog/help/what-is-a-catch-all-or-accept-all/) address? | `smtp.is_catch_all` |
+| 🔜 | **Role account validation** | Is the email address a well-known role account? | [Issue #88](https://github.com/amaurymartiny/check-if-email-exists/issues/88) |
+| 🔜 | **Free email provider check** | Is the email address bound to a known free email provider? | [Issue #89](https://github.com/amaurymartiny/check-if-email-exists/issues/89) |
+| 🔜 | **Syntax validation, provider-specific** | According to the syntactic rules of the target mail provider, is the address syntactically valid? | [Issue #90](https://github.com/amaurymartiny/check-if-email-exists/issues/90) |
+| 🔜 | **Honeypot detection** | Does email address under test hide a [honeypot](https://en.wikipedia.org/wiki/Spamtrap)? | [Issue #91](https://github.com/amaurymartiny/check-if-email-exists/issues/91) |
+| 🔜 | **Gravatar** | Does this email address have a [Gravatar](https://gravatar.com/) profile picture? | [Issue #92](https://github.com/amaurymartiny/check-if-email-exists/issues/92) |
## 🤔 Why?
@@ -53,9 +42,9 @@ Many online services (https://hunter.io, http://verify-email.org, http://email-c
There are 4 ways you can try `check-if-email-exists`.
-### 1. Use the Hosted Version
+### 1. Use the Hosted Version: http://reacherhq.github.io
-I created a simple static site with this tool hosted on an AWS Lambda serverless backend: http://reacherhq.github.io. The Lambda endpoint is rate-limited to prevent abuse. Also see [issue #155](https://github.com/amaurymartiny/check-if-email-exists/issues/155).
+I created a simple static site with this tool: http://reacherhq.github.io. The check-if-email-exists is hosted on [fly.io](https://fly.io). The check-if-email-exists endpoint is rate-limited to prevent abuse. Also see [issue #155](https://github.com/amaurymartiny/check-if-email-exists/issues/155).
If you would like to self-host it yourself and have questions, send me a message.
@@ -87,7 +76,7 @@ Optionally, you can also pass in `from_email` and `hello_name` fields into the J
### 3. Download the Binary
-> Note: The binary doesn't connect to any backend, it checks the email directly from your computer.
+> Note: The binary doesn't connect to any check-if-email-exists, it checks the email directly from your computer.
Head to the [releases page](https://github.com/amaurymartiny/check-if-email-exists/releases) and download the binary for your platform. Make sure you have [`openssl`](https://www.openssl.org/) installed on your local machine.
@@ -111,6 +100,9 @@ OPTIONS:
`--http` flag is on. [default: 127.0.0.1]
--http-port <PORT> Sets the port on which the HTTP server should bind. Only used when `--http` flag is
on. If not set, then it will use $PORT, or default to 3000.
+ --proxy-host <PROXY_HOST> Use the specified SOCKS5 proxy host to perform email verification.
+ --proxy-port <PROXY_PORT> Use the specified SOCKS5 proxy port to perform email verification. Only used when
+ `--proxy-host` flag is set. [default: 1080]
ARGS:
<TO_EMAIL> The email to check.
@@ -147,15 +139,28 @@ In your own Rust project, you can add `check-if-email-exists` in your `Cargo.tom
check-if-email-exists = "0.7"
```
-And use it in your code as follows (async/await syntax):
+And use it in your code as follows:
```rust
-use check_if_email_exists::email_exists;
+use check_if_email_exists::{email_exists, EmailInput};
-// First arg is the email we want to check, second arg is the FROM email used in the SMTP connection
-let checked = email_exists("[email protected]", "[email protected]").await;
+async fn check() {
+ // Let's say we want to test the deliverability of [email protected].
+ let mut input = EmailInput::new("[email protected]".into());
-println!("{:?}", checked); // `checked` is a SingleEmail struct, see docs for more info
+ // Optionally, we can also tweak the configuration parameters used in the
+ // verification.
+ input
+ .from_email("[email protected]".into()) // Used in the `MAIL FROM:` command
+ .hello_name("example.org".into()); // Used in the `EHLO` command
+
+ // Verify this input, using async/await syntax.
+ let result = email_exists(&input).await;
+
+ // `result` is a `SingleEmail` struct containing all information about the
+ // email.
+ println!("{:?}", result);
+}
```
The reference docs are hosted on [docs.rs](https://docs.rs/check-if-email-exists).
@@ -188,8 +193,8 @@ The output will be a JSON with the below format, the fields should be self-expla
"syntax": {
"address": "[email protected]",
"domain": "gmail.com",
- "username": "someone",
- "valid_format": true
+ "is_valid_syntax": true,
+ "username": "someone"
}
}
```
@@ -198,11 +203,11 @@ The output will be a JSON with the below format, the fields should be self-expla
### The library hangs/takes a long time/doesn't show anything after 1 minute.
-Most ISPs block outgoing SMTP requests through ports 25, 587 and 465, to prevent spam. `check-if-email-exists` needs to have these ports open to make a connection to the email's SMTP server, so won't work behind these ISPs, and will instead hang until it times out. There's unfortunately no easy workaround for this problem, see for example [this StackOverflow thread](https://stackoverflow.com/questions/18139102/how-to-get-around-an-isp-block-on-port-25-for-smtp). One solution is to rent a Linux cloud server with a static IP and no blocked ports.
+Most ISPs block outgoing SMTP requests through port 25, to prevent spam. `check-if-email-exists` needs to have this port open to make a connection to the email's SMTP server, so won't work behind these ISPs, and will instead hang until it times out. There's unfortunately no easy workaround for this problem, see for example [this StackOverflow thread](https://stackoverflow.com/questions/18139102/how-to-get-around-an-isp-block-on-port-25-for-smtp). One solution is to rent a Linux cloud server with a static IP and no blocked ports.
-To see in details what the binary is doing behind the scenes, run it in [verbose mode](#verbose-mode) to see the logs.
+To see in details what the binary is doing behind the scenes, run it in verbose mode to see the logs.
-### The output shows `"connection refused"` in the `smtp` field.
+### The output shows `"connection refused"` in the `smtp.error` field.
This also happens when your ISP block SMTP ports, see the above answer.
@@ -222,7 +227,7 @@ $ cargo build --release
$ ./target/release/check_if_email_exists --help
```
-## 👣 Legacy Bash Script
+## Legacy Bash Script
The 1st version of this tool was a simple bash script which made a telnet call. If you would like to use that simpler version, have a look at the [`legacy`](https://github.com/amaurymartiny/check-if-email-exists/tree/legacy) branch. The reasons for porting the bash script to the current codebase are explained [in this issue](https://github.com/amaurymartiny/check-if-email-exists/issues/4).
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 5057e31d..9535fd33 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -14,6 +14,47 @@
// You should have received a copy of the GNU General Public License
// along with check-if-email-exists. If not, see <http://www.gnu.org/licenses/>.
+//! `check-if-email-exists` lets you check if an email address exists without
+//! sending any email.
+//!
+//! Under the hood, it connects to the email address's SMTP server, and,
+//! analyzing the server's responses against some SMTP commands, finds out
+//! information about the email address, such as:
+//! - Email deliverability: Is an email sent to this address deliverable?
+//! - Syntax validation. Is the address syntactically valid?
+//! - DNS records validation. Does the domain of the email address have valid
+//! MX DNS records?
+//! - Disposable email address (DEA) validation. Is the address provided by a
+//! known disposable email address provider?
+//! - SMTP server validation. Can the mail exchanger of the email address
+//! domain be contacted successfully?
+//! - Mailbox disabled. Has this email address been disabled by the email
+//! provider?
+//! - Full inbox. Is the inbox of this mailbox full?
+//! - Catch-all address. Is this email address a catch-all address?
+//!
+//! ```rust
+//! use check_if_email_exists::{email_exists, EmailInput};
+//!
+//! async fn check() {
+//! // Let's say we want to test the deliverability of [email protected].
+//! let mut input = EmailInput::new("[email protected]".into());
+//!
+//! // Optionally, we can also tweak the configuration parameters used in the
+//! // verification.
+//! input
+//! .from_email("[email protected]".into()) // Used in the `MAIL FROM:` command
+//! .hello_name("example.org".into()); // Used in the `EHLO` command
+//!
+//! // Verify this input, using async/await syntax.
+//! let result = email_exists(&input).await;
+//!
+//! // `result` is a `SingleEmail` struct containing all information about the
+//! // email.
+//! println!("{:?}", result);
+//! }
+//! ```
+
#[macro_use]
extern crate log;
diff --git a/core/src/syntax.rs b/core/src/syntax.rs
index e2178320..aeaead3a 100644
--- a/core/src/syntax.rs
+++ b/core/src/syntax.rs
@@ -26,10 +26,10 @@ pub struct SyntaxDetails {
pub address: EmailAddress,
/// The domain name, after "@"
pub domain: String,
+ /// Does the email have a valid syntax?
+ pub is_valid_syntax: bool,
/// The username, before "@"
pub username: String,
- /// Is the email in a valid format?
- pub valid_format: bool,
}
#[derive(Debug, Serialize)]
@@ -73,8 +73,8 @@ pub fn address_syntax(email_address: &str) -> Result<SyntaxDetails, SyntaxError>
let address_details = SyntaxDetails {
address: email_address,
domain,
+ is_valid_syntax: true,
username,
- valid_format: true,
};
Ok(address_details)
@@ -111,8 +111,8 @@ mod tests {
Ok(SyntaxDetails {
address: EmailAddress::new("[email protected]".into()).unwrap(),
domain: "bar.com".into(),
+ is_valid_syntax: true,
username: "foo".into(),
- valid_format: true
})
);
}
diff --git a/core/src/util/email_input.rs b/core/src/util/email_input.rs
index 0501b5ad..05719dd8 100644
--- a/core/src/util/email_input.rs
+++ b/core/src/util/email_input.rs
@@ -15,7 +15,7 @@
// along with check-if-email-exists. If not, see <http://www.gnu.org/licenses/>.
/// Perform the email verification via a specified proxy. The usage of a proxy
-/// is of course optional.
+/// is optional.
pub struct EmailInputProxy {
/// Use the specified SOCKS5 proxy host to perform email verification.
pub host: String,
@@ -37,7 +37,7 @@ pub struct EmailInput {
/// Defaults to "localhost" (note: "localhost" is not a FQDN).
pub hello_name: String,
/// Perform the email verification via a specified proxy. The usage of a
- /// proxy is of course optional.
+ /// proxy is optional.
pub proxy: Option<EmailInputProxy>,
}
diff --git a/test_suite/src/lib.rs b/test_suite/src/lib.rs
index a6f31bb0..65901193 100644
--- a/test_suite/src/lib.rs
+++ b/test_suite/src/lib.rs
@@ -41,7 +41,7 @@ mod tests {
assert_eq!(
serde_json::to_string(&result).unwrap(),
- "{\"input\":\"[email protected]\",\"misc\":{\"error\":{\"type\":\"Skipped\"}},\"mx\":{\"error\":{\"type\":\"ResolveError\",\"message\":\"no record found for name: bar.baz type: MX class: IN\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"address\":\"[email protected]\",\"domain\":\"bar.baz\",\"username\":\"foo\",\"valid_format\":true}}"
+ "{\"input\":\"[email protected]\",\"misc\":{\"error\":{\"type\":\"Skipped\"}},\"mx\":{\"error\":{\"type\":\"ResolveError\",\"message\":\"no record found for name: bar.baz type: MX class: IN\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"address\":\"[email protected]\",\"domain\":\"bar.baz\",\"is_valid_syntax\":true,\"username\":\"foo\"}}"
);
}
}