Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.
Rust emailemail-validationemail-validation-apiemail-verificationemail-verification-apiemail-verifierhacktoberfest
feat: Add possibility to set SMTP port (#985)
Amaurycdabdf80e858
diff --git a/Cargo.lock b/Cargo.lockindex 1c33bdfa..34d2dabc 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -307,7 +307,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"[[package]]name = "check-if-email-exists"-version = "0.8.24"+version = "0.8.25"dependencies = ["async-native-tls","async-smtp",@@ -328,7 +328,7 @@ dependencies = [[[package]]name = "check-if-email-exists-cli"-version = "0.8.24"+version = "0.8.25"dependencies = ["check-if-email-exists","clap",diff --git a/Cargo.toml b/Cargo.tomlindex c979593b..54292461 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,6 +1,6 @@[package]name = "check-if-email-exists-cli"-version = "0.8.24"+version = "0.8.25"default-run = "check_if_email_exists"edition = "2018"description = "Check if an email address exists without sending any email."diff --git a/README.md b/README.mdindex 60ace820..bb0229e1 100644--- a/README.md+++ b/README.md@@ -1,8 +1,6 @@[](https://crates.io/crates/check-if-email-exists)[](https://docs.rs/check-if-email-exists)[](https://github.com/reacherhq/check-if-email-exists/actions)-[](https://travis-ci.com/reacherhq/check-if-email-exists)-[](https://ci.appveyor.com/project/amaurym/check-if-email-exists)[](https://github.com/sponsors/amaurym)<br /><br /><br />@@ -78,29 +76,9 @@ For an one-click deploy to [Heroku](https://heroku.com), click on the purple Her### 3. Use Docker-The [Docker image](./Dockerfile) is hosted on Docker Hub: https://hub.docker.com/r/reacherhq/check-if-email-exists.+A Docker image with a fully-fledged HTTP backend is hosted on https://hub.docker.com/r/reacherhq/backend.-To run it, run the following command:--```bash-docker run -p 3000:3000 reacherhq/check-if-email-exists-```--You can then send a POST request with the following body to `http://localhost:3000` to test multiple emails at once:--```json-{- "to_emails": ["[email protected]"]-}-```--Here's the equivalent `curl` command:--```bash-curl -X POST -d'{"to_emails":["[email protected]"]}' http://localhost:3000-```--Optionally, you can also pass in `from_email` and `hello_name` fields into the JSON object, see the help message below to understand their meanings.+For more information on how to use the Docker image, please head to [reacherhq/backend](https://github.com/reacherhq/backend#2-use-docker).### 4. Download the Binary@@ -110,50 +88,52 @@ Head to the [releases page](https://github.com/reacherhq/check-if-email-exists/r```> $ check_if_email_exists --help-check_if_email_exists 0.8.24+check_if_email_exists 0.8.25Check if an email address exists without sending any email.USAGE:check_if_email_exists [FLAGS] [OPTIONS] [TO_EMAIL]+ARGS:+ <TO_EMAIL> The email to check+FLAGS:- --http Runs a HTTP server.- -h, --help Prints help information- -V, --version Prints version information+ -h, --help Print help information+ --http DEPRECATED. Runs a HTTP server. This option will be removed in v0.9.0+ -V, --version Print version informationOPTIONS:- --from-email <FROM_EMAIL> The email to use in the `MAIL FROM:` SMTP command. [default:- --hello-name <HELLO_NAME> The name to use in the `EHLO:` SMTP command. [default: localhost]- --http-host <HOST> Sets the host IP address on which the HTTP server should bind. Only used when- `--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]- --yahoo-use-api <YAHOO_USE_API> For Yahoo email addresses, use Yahoo's API instead of connecting directly to- their SMTP servers. [default: true]+ --from-email <FROM_EMAIL>+ The email to use in the `MAIL FROM:` SMTP command [env: FROM_EMAIL=] [default:-ARGS:- <TO_EMAIL> The email to check.-```+ --hello-name <HELLO_NAME>+ The name to use in the `EHLO:` SMTP command [env: HELLO_NAME=] [default: localhost]-If you run with the `--http` flag, `check-if-email-exists` will serve a HTTP server on `http://localhost:3000`. You can then send a POST request with the following body to test multiple emails at once:+ --http-host <HTTP_HOST>+ DEPRECATED. Sets the host IP address on which the HTTP server should bind. Only used+ when `--http` flag is on. This option will be removed in v0.9.0 [env: HOST=] [default:+ 127.0.0.1]-```json-{- "to_emails": ["[email protected]"]-}-```+ --http-port <HTTP_PORT>+ DEPRECATED. 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. This option will be+ removed in v0.9.0 [env: PORT=] [default: 3000]-Here's the equivalent `curl` command:+ --proxy-host <PROXY_HOST>+ Use the specified SOCKS5 proxy host to perform email verification [env: PROXY_HOST=]-```bash-curl -X POST -d'{"to_emails":["[email protected]"]}' http://localhost:3000-```+ --proxy-port <PROXY_PORT>+ Use the specified SOCKS5 proxy port to perform email verification. Only used when+ `--proxy-host` flag is set [env: PROXY_PORT=] [default: 1080]++ --smtp-port <SMTP_PORT>+ The email to check [env: SMTP_PORT=] [default: 25]-Optionally, you can also pass in `from_email` and `hello_name` fields into the JSON object, see the help message above to understand their meanings.+ --yahoo-use-api <YAHOO_USE_API>+ For Yahoo email addresses, use Yahoo's API instead of connecting directly to their SMTP+ servers [env: YAHOO_USE_API=] [default: true]+```**💡 PRO TIP:** To show debug logs when running the binary, run:diff --git a/core/Cargo.toml b/core/Cargo.tomlindex c78b4bd7..ce28f5b6 100644--- a/core/Cargo.toml+++ b/core/Cargo.toml@@ -1,6 +1,6 @@[package]name = "check-if-email-exists"-version = "0.8.24"+version = "0.8.25"authors = ["Amaury <[email protected]>"]categories = ["email"]description = "Check if an email address exists without sending any email"diff --git a/core/src/lib.rs b/core/src/lib.rsindex 3a18598d..cc2644b4 100644--- a/core/src/lib.rs+++ b/core/src/lib.rs@@ -45,7 +45,8 @@//! input//! .set_from_email("[email protected]".into()) // Used in the `MAIL FROM:` command//! .set_hello_name("example.org".into()) // Used in the `EHLO` command-//! .set_proxy(CheckEmailInputProxy { // Use a SOCKS5 proxy to verify the email+//! .set_smtp(587) // Use port 587 instead of 25+//! .set_proxy(CheckEmailInputProxy { // Use a SOCKS5 proxy to verify the email//! host: "my-proxy.io".into(),//! port: 1080//! });@@ -65,7 +66,6 @@ pub mod smtp;pub mod syntax;mod util;-use async_smtp::smtp::SMTP_PORT;use futures::future;use misc::{check_misc, MiscDetails};use mx::check_mx;@@ -173,8 +173,7 @@ async fn check_single_email(input: CheckEmailInput) -> CheckEmailOutput {.as_ref().expect("We already checked that the email has valid format. qed."),host.exchange(),- // FIXME We could add ports 465 and 587 too.- SMTP_PORT,+ input.smtp_port,my_syntax.domain.as_ref(),&input,)@@ -215,6 +214,7 @@ pub async fn check_email(inputs: &CheckEmailInput) -> Vec<CheckEmailOutput> {from_email: inputs.from_email.clone(),hello_name: inputs.hello_name.clone(),proxy: inputs.proxy.clone(),+ smtp_port: inputs.smtp_port,smtp_timeout: inputs.smtp_timeout,yahoo_use_api: inputs.yahoo_use_api,}diff --git a/core/src/util/input_output.rs b/core/src/util/input_output.rsindex 85769a8e..190aecb0 100644--- a/core/src/util/input_output.rs+++ b/core/src/util/input_output.rs@@ -48,6 +48,11 @@ pub struct CheckEmailInput {/// Perform the email verification via the specified SOCK5 proxy. The usage of a/// proxy is optional.pub proxy: Option<CheckEmailInputProxy>,+ /// SMTP port to use for email validation. Generally, ports 25, 465, 587+ /// and 2525 are used.+ ///+ /// Defaults to 25.+ pub smtp_port: u16,/// Add optional timeout for the SMTP verification step.pub smtp_timeout: Option<Duration>,/// For Yahoo email addresses, use Yahoo's API instead of connecting@@ -64,6 +69,7 @@ impl Default for CheckEmailInput {from_email: "[email protected]".into(),hello_name: "localhost".into(),proxy: None,+ smtp_port: 25,smtp_timeout: None,yahoo_use_api: true,}@@ -132,6 +138,12 @@ impl CheckEmailInput {self}+ /// Change the SMTP port.+ pub fn set_smtp_port(&mut self, port: u16) -> &mut CheckEmailInput {+ self.smtp_port = port;+ self+ }+/// Add optional timeout for the SMTP verification step.pub fn set_smtp_timeout(&mut self, duration: Duration) -> &mut CheckEmailInput {self.smtp_timeout = Some(duration);diff --git a/src/main.rs b/src/main.rsindex c07bae42..dabf64a6 100644--- a/src/main.rs+++ b/src/main.rs@@ -43,6 +43,10 @@ pub struct Cli {#[clap(long, env, default_value = "1080")]pub proxy_port: u16,+ /// The port to use for the SMTP request.+ #[clap(long, env, default_value = "25")]+ pub smtp_port: u16,+/// For Yahoo email addresses, use Yahoo's API instead of connecting/// directly to their SMTP servers.#[clap(long, env, default_value = "true", parse(try_from_str))]@@ -94,6 +98,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {input.set_from_email(CONF.from_email.clone()).set_hello_name(CONF.hello_name.clone())+ .set_smtp_port(CONF.smtp_port).set_yahoo_use_api(CONF.yahoo_use_api);if let Some(proxy_host) = &CONF.proxy_host {input.set_proxy(CheckEmailInputProxy {