Skip to content

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

feat: Add serverless function (#15)

Amaury Martiny532c4ebcb4a9
diff --git a/.gitignore b/.gitignore
index ecbd5bb6..15588c0e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
.DS_Store
+.serverless
diff --git a/Cargo.lock b/Cargo.lock
index b5b5b0bb..40c79f66 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ dependencies = [
[[package]]
name = "aho-corasick"
-version = "0.6.10"
+version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -43,7 +43,7 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
- "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -118,27 +118,56 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "check_if_email_exists"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
- "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "check_if_email_exists_core 0.1.2",
+ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lettre 0.9.0 (git+https://github.com/lettre/lettre?rev=1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb)",
+]
+
+[[package]]
+name = "check_if_email_exists_core"
+version = "0.1.2"
+dependencies = [
+ "lettre 0.9.0 (git+https://github.com/lettre/lettre?rev=1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"trust-dns-resolver 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "check_if_email_exists_serverless"
+version = "0.1.2"
+dependencies = [
+ "check_if_email_exists_core 0.1.2",
+ "lambda_http 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lettre 0.9.0 (git+https://github.com/lettre/lettre?rev=1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "chrono"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "clap"
-version = "2.32.0"
+version = "2.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -239,6 +268,11 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "dtoa"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "either"
version = "1.5.1"
@@ -252,7 +286,7 @@ dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -334,6 +368,32 @@ name = "futures"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "futures-cpupool"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "h2"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "hostname"
version = "0.1.5"
@@ -343,6 +403,21 @@ dependencies = [
"winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "http"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "httparse"
+version = "1.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "humantime"
version = "1.2.0"
@@ -351,6 +426,33 @@ dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "hyper"
+version = "0.12.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-threadpool 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "idna"
version = "0.1.5"
@@ -361,6 +463,11 @@ dependencies = [
"unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "indexmap"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "iovec"
version = "0.1.2"
@@ -396,6 +503,91 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "lambda_http"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lambda_runtime"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime_core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lambda_runtime_client"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hyper 0.12.28 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime_errors 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lambda_runtime_core"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hyper 0.12.28 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime_client 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime_errors 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lambda_runtime_errors"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lambda_runtime_errors_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lambda_runtime_errors_derive"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "lazy_static"
version = "1.3.0"
@@ -553,6 +745,19 @@ dependencies = [
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "num-integer"
+version = "0.1.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "num_cpus"
version = "1.10.0"
@@ -561,6 +766,11 @@ dependencies = [
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "numtoa"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "openssl"
version = "0.10.20"
@@ -803,19 +1013,19 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.1.2"
+version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
-version = "0.6.5"
+version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -929,6 +1139,17 @@ dependencies = [
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "serde_urlencoded"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "slab"
version = "0.4.2"
@@ -955,9 +1176,14 @@ name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "string"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "strsim"
-version = "0.7.0"
+version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -1004,17 +1230,18 @@ dependencies = [
[[package]]
name = "termion"
-version = "1.5.1"
+version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
-version = "0.10.0"
+version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1028,6 +1255,16 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "time"
+version = "0.1.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "tokio"
version = "0.1.18"
@@ -1247,6 +1484,11 @@ dependencies = [
"trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "try-lock"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "ucd-util"
version = "0.1.3"
@@ -1308,6 +1550,16 @@ name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "want"
+version = "0.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "widestring"
version = "0.2.2"
@@ -1391,7 +1643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf9f0d0b1cc33a4d2aee14fb4b2eac03462ef4db29c8ac4057327d8a71ad86f"
-"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
+"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
"checksum ascii_utils 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a"
@@ -1406,7 +1658,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
-"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
+"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
+"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
@@ -1417,6 +1670,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
"checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c"
+"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac"
"checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a"
"checksum error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46"
@@ -1430,13 +1684,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
+"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
+"checksum h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "85ab6286db06040ddefb71641b50017c06874614001a134b423783e2db2920bd"
"checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e"
+"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a"
+"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
+"checksum hyper 0.12.28 (registry+https://github.com/rust-lang/crates.io-index)" = "e8e4606fed1c162e3a63d408c07584429f49a4f34c7176cb6cbee60e78f2372c"
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
+"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum ipconfig 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+"checksum lambda_http 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a935998dc010d1d7e8d466d3e3dddae9bd51dc111da487634efd3265fe20d6ac"
+"checksum lambda_runtime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "077b8819fe6998266342efdc5154192551143f390ab758007cc7421992e61b07"
+"checksum lambda_runtime_client 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e64758b587f1d07b6ca4814a3bc0f3db48c89cc3c895db43a23c690855b370"
+"checksum lambda_runtime_core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "da1cb59e060c1068cfa386b58c202a4381c509ace85a1eadab505164f0563ca5"
+"checksum lambda_runtime_errors 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "93b63ea3688df164aaa5643c5f3291cc481366d624729deb3c4dc85ee65ac20a"
+"checksum lambda_runtime_errors_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "38fa619ec6f1ee2371a109683d251035c83f01b8ffc10f4aa46de821836a7baf"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
"checksum lettre 0.9.0 (git+https://github.com/lettre/lettre?rev=1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb)" = "<none>"
@@ -1455,7 +1721,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
+"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
+"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
+"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
@@ -1483,8 +1752,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
-"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f"
-"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
+"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58"
+"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
@@ -1499,18 +1768,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c"
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
+"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
-"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
+"checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b"
+"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
-"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
-"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
+"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
+"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
+"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "65641e515a437b308ab131a82ce3042ff9795bef5d6c5a9be4eb24195c417fd9"
"checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f"
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443"
@@ -1527,6 +1799,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "09144f0992b0870fa8d2972cc069cbf1e3c0fda64d1f3d45c4d68d0e0b52ad4e"
"checksum trust-dns-resolver 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8a9f877f7a1ad821ab350505e1f1b146a4960402991787191d6d8cab2ce2de2c"
+"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
@@ -1537,6 +1810,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
+"checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3"
"checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
diff --git a/Cargo.toml b/Cargo.toml
index 5dd02958..9c3795f1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,21 +1,6 @@
-[package]
-name = "check_if_email_exists"
-version = "0.1.1"
-authors = ["Amaury Martiny <[email protected]>"]
-
-[lib]
-path = "src/lib.rs"
-
-[[bin]]
-name = "check_if_email_exists"
-path = "src/bin/main.rs"
-doc = false
-
-[dependencies]
-clap = {version = "2.32", features = ["yaml"]}
-env_logger = "0.6"
-lettre = { git = "https://github.com/lettre/lettre", rev = "1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb" }
-log = "0.4"
-native-tls = "^0.2"
-rayon = "1.0.3"
-trust-dns-resolver = "0.10.2"
+[workspace]
+members = [
+ "check_if_email_exists",
+ "cli",
+ "serverless"
+]
diff --git a/README.md b/README.md
index 01d7df4b..19d35436 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,10 @@ Check if an email address exists before sending the email.
[![](https://img.shields.io/travis/amaurymartiny/check_if_email_exists.svg)](https://travis-ci.org/amaurymartiny/check_if_email_exists)
[![](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)
+Try it here: https://y78n51qcpj.execute-api.us-east-1.amazonaws.com/dev/?to_email=PUT_YOUR_EMAIL_HERE
+
+> Note: The operation might take up to 1 minute.
+
## Why?
Many online services (https://hunter.io, http://verify-email.org, http://email-checker.net) offer this service for a paid fee. Here is an open-source alternative to those tools.
@@ -26,7 +30,7 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
- --from <FROM_EMAIL> The from email to use in the SMTP connection (default: [email protected])
+ --from <FROM_EMAIL> The from email to use in the SMTP connection (default: [email protected])
ARGS:
<TO_EMAIL> The email to check
@@ -42,7 +46,7 @@ RUST_LOG=debug check_if_email_exists [OPTIONS] <TO_EMAIL>
## FAQ
-### The binary hangs/takes a long time/doesn't show anything.
+### The binary 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.
diff --git a/check_if_email_exists/Cargo.toml b/check_if_email_exists/Cargo.toml
new file mode 100644
index 00000000..6fd1b505
--- /dev/null
+++ b/check_if_email_exists/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "check_if_email_exists_core"
+version = "0.1.2"
+authors = ["Amaury Martiny <[email protected]>"]
+edition = "2018"
+
+[dependencies]
+lettre = { git = "https://github.com/lettre/lettre", rev = "1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb" }
+log = "0.4"
+native-tls = "^0.2"
+rayon = "1.0.3"
+trust-dns-resolver = "0.10.2"
diff --git a/src/lib.rs b/check_if_email_exists/src/lib.rs
similarity index 55%
rename from src/lib.rs
rename to check_if_email_exists/src/lib.rs
index 872543fe..e0e5faad 100644
--- a/src/lib.rs
+++ b/check_if_email_exists/src/lib.rs
@@ -6,28 +6,37 @@ extern crate rayon;
extern crate trust_dns_resolver;
use lettre::smtp::{SMTP_PORT, SUBMISSIONS_PORT, SUBMISSION_PORT};
+use lettre::EmailAddress;
use rayon::prelude::*;
-use std::process;
mod mx_hosts;
mod smtp;
-pub fn email_exists(from_email: &str, to_email: &str) -> Option<bool> {
+/// Errors that are returned by email_exists
+#[derive(Debug)]
+pub enum EmailExistsError {
+ BlockedByIsp,
+}
+
+pub fn email_exists(
+ from_email: &EmailAddress,
+ to_email: &EmailAddress,
+) -> Result<bool, EmailExistsError> {
debug!("Checking 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);
- }
- };
+ let domain = to_email.to_string();
+ let domain = domain
+ .as_str()
+ .split("@")
+ .skip(1)
+ .next()
+ .expect("We checked above that email is valid. qed.");
debug!("Domain name is '{}'", domain);
debug!("Getting MX lookup...");
let hosts = mx_hosts::get_mx_lookup(domain);
debug!("Found the following MX hosts {:?}", hosts);
- let ports = vec![SMTP_PORT, SUBMISSION_PORT, SUBMISSIONS_PORT]; // 25, 587, 465
+ let ports = vec![SMTP_PORT, SUBMISSION_PORT, SUBMISSIONS_PORT]; // [25, 587, 465]
let mut combinations = Vec::new(); // `(host, port)` combination
for port in ports.into_iter() {
for host in hosts.iter() {
@@ -38,6 +47,9 @@ pub fn email_exists(from_email: &str, to_email: &str) -> Option<bool> {
combinations
// Parallely find any combination that returns true for email_exists
.par_iter()
- .flat_map(|(host, port)| smtp::email_exists(from_email, to_email, host, *port))
+ .flat_map(|(host, port)| smtp::email_exists_on_host(from_email, to_email, host, *port))
.find_any(|_| true)
+ // If all smtp calls timed out/got refused/errored, we assume that the
+ // ISP is blocking relevant ports
+ .ok_or(EmailExistsError::BlockedByIsp)
}
diff --git a/src/mx_hosts.rs b/check_if_email_exists/src/mx_hosts.rs
similarity index 100%
rename from src/mx_hosts.rs
rename to check_if_email_exists/src/mx_hosts.rs
diff --git a/src/smtp.rs b/check_if_email_exists/src/smtp.rs
similarity index 79%
rename from src/smtp.rs
rename to check_if_email_exists/src/smtp.rs
index 439f7bf6..bccc8ec7 100644
--- a/src/smtp.rs
+++ b/check_if_email_exists/src/smtp.rs
@@ -7,7 +7,7 @@ use lettre::EmailAddress;
use std::time::Duration;
use trust_dns_resolver::Name;
-// Try to send an smtp command, close if fails.
+/// Try to send an smtp command, close and return Err if fails.
macro_rules! try_smtp (
($res: expr, $client: ident, $host: expr, $port: expr) => ({
if let Err(err) = $res {
@@ -18,9 +18,10 @@ macro_rules! try_smtp (
})
);
-pub fn email_exists(
- from_email: &str,
- to_email: &str,
+/// Check if `to_email` exists on host server with given port
+pub fn email_exists_on_host(
+ from_email: &EmailAddress,
+ to_email: &EmailAddress,
host: &Name,
port: u16,
) -> Result<bool, Error> {
@@ -52,21 +53,19 @@ pub fn email_exists(
);
// Send from.
+ // FIXME Do not clone?
+ let from_email_clone = from_email.clone();
try_smtp!(
- smtp_client.command(MailCommand::new(
- Some(EmailAddress::new(from_email.to_string()).unwrap()),
- vec![],
- )),
+ smtp_client.command(MailCommand::new(Some(from_email_clone), vec![],)),
smtp_client,
host,
port
);
// Send to.
- let result = match smtp_client.command(RcptCommand::new(
- EmailAddress::new(to_email.to_string()).unwrap(),
- vec![],
- )) {
+ // FIXME Do not clone?
+ let to_email_clone = to_email.clone();
+ let result = match smtp_client.command(RcptCommand::new(to_email_clone, vec![])) {
Ok(response) => match response.first_line() {
Some(message) => {
// 250 2.1.5 Recipient e-mail address ok.
diff --git a/ci/script.sh b/ci/script.sh
index e64b68a5..fd3cc920 100755
--- a/ci/script.sh
+++ b/ci/script.sh
@@ -17,8 +17,8 @@ main() {
# Run the binary with a $TEST_EMAIL, to test that the tool actually works.
# TODO This only works on osx now, see #11
if [ $TRAVIS_OS_NAME = osx ]; then
- cross run --target $TARGET $TEST_EMAIL | grep true
- cross run --target $TARGET --release $TEST_EMAIL | grep true
+ cross run --target $TARGET --bin check_if_email_exists $TEST_EMAIL | grep true
+ cross run --target $TARGET --release --bin check_if_email_exists $TEST_EMAIL | grep true
fi
}
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
new file mode 100644
index 00000000..447ad6d2
--- /dev/null
+++ b/cli/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "check_if_email_exists"
+version = "0.1.2"
+authors = ["Amaury Martiny <[email protected]>"]
+edition = "2018"
+
+[dependencies]
+check_if_email_exists_core = { path = "../check_if_email_exists" }
+clap = { version = "2.32", features = ["yaml"] }
+env_logger = "0.6"
+lettre = { git = "https://github.com/lettre/lettre", rev = "1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb" }
diff --git a/src/bin/cli.yml b/cli/src/cli.yml
similarity index 100%
rename from src/bin/cli.yml
rename to cli/src/cli.yml
diff --git a/cli/src/main.rs b/cli/src/main.rs
new file mode 100644
index 00000000..22ecd211
--- /dev/null
+++ b/cli/src/main.rs
@@ -0,0 +1,46 @@
+extern crate env_logger;
+#[macro_use]
+extern crate clap;
+extern crate check_if_email_exists_core;
+extern crate lettre;
+
+use check_if_email_exists_core::email_exists;
+use clap::App;
+use lettre::EmailAddress;
+use std::process;
+use std::str::FromStr;
+
+/// Log error and exit immediately if there's one
+macro_rules! try_or_exit (
+ ($res: expr) => ({
+ match $res {
+ Ok(value) => value,
+ Err(err) => {
+ println!("{:?}", err);
+ process::exit(1)
+ }
+ }
+ })
+);
+
+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 = try_or_exit!(EmailAddress::from_str(
+ matches.value_of("FROM_EMAIL").unwrap_or("[email protected]")
+ ));
+ let to_email = try_or_exit!(EmailAddress::from_str(
+ matches
+ .value_of("TO_EMAIL")
+ .expect("'TO_EMAIL' is required. qed.")
+ ));
+
+ println!("This operation can take up to 1 minute, please be patient...");
+ let exists = try_or_exit!(email_exists(&from_email, &to_email));
+
+ println!("{}", exists)
+}
diff --git a/serverless.yml b/serverless.yml
new file mode 100644
index 00000000..7522a26b
--- /dev/null
+++ b/serverless.yml
@@ -0,0 +1,21 @@
+service: check-if-email-exists
+provider:
+ name: aws
+ runtime: rust
+plugins:
+ # this adds informs servleress to use
+ # the serverless-rust plugin
+ - serverless-rust
+# creates one artifact for each function
+package:
+ individually: true
+functions:
+ check_if_email_exists_serverless:
+ # handler value syntax is `{cargo-package-name}.{bin-name}`
+ # or `{cargo-package-name}` for short when you are building a
+ # default bin for a given package.
+ handler: check_if_email_exists_serverless
+ events:
+ - http:
+ path: /
+ method: GET
diff --git a/serverless/Cargo.toml b/serverless/Cargo.toml
new file mode 100644
index 00000000..23135735
--- /dev/null
+++ b/serverless/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "check_if_email_exists_serverless"
+version = "0.1.2"
+authors = ["Amaury Martiny <[email protected]>"]
+edition = "2018"
+
+[dependencies]
+check_if_email_exists_core = { path = "../check_if_email_exists" }
+lambda_http = "0.1"
+lambda_runtime = "0.2"
+lettre = { git = "https://github.com/lettre/lettre", rev = "1cbcbbb11f7a39a5d5d3829ce4162ca1beafedfb" }
+serde_json = "1.0"
diff --git a/serverless/README.md b/serverless/README.md
new file mode 100644
index 00000000..bcbbd4b6
--- /dev/null
+++ b/serverless/README.md
@@ -0,0 +1,29 @@
+# Serverless
+
+This package deploys the `check_if_email_exists` function as a lambda function on AWS via [serverless](https://serverless.com/).
+
+To try it out, follow the steps below:
+
+#### Set up `serverless`
+
+Follow serverless's guide: https://serverless.com/framework/docs/providers/aws/guide/quick-start/.
+
+#### Invoke the function locally change `[email protected]` to the email your wish to test inside `payload.json`, and run from the root folder:
+
+Note: you need to have Docker installed.
+
+```bash
+serverless invoke local -f check_if_email_exists_serverless -d "$(cat serverless/payload.json)"
+```
+
+#### Deploy the function to AWS
+
+```bash
+serverless deploy
+```
+
+#### Invoke the deployed function
+
+```bash
+serverless invoke -f check_if_email_exists_serverless -d "$(cat serverless/payload.json)"
+```
diff --git a/serverless/payload.json b/serverless/payload.json
new file mode 100644
index 00000000..fca644d3
--- /dev/null
+++ b/serverless/payload.json
@@ -0,0 +1,55 @@
+{
+ "path": "/",
+ "headers": {
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
+ "Accept-Encoding": "gzip, deflate, lzma, sdch, br",
+ "Accept-Language": "en-US,en;q=0.8",
+ "CloudFront-Forwarded-Proto": "https",
+ "CloudFront-Is-Desktop-Viewer": "true",
+ "CloudFront-Is-Mobile-Viewer": "false",
+ "CloudFront-Is-SmartTV-Viewer": "false",
+ "CloudFront-Is-Tablet-Viewer": "false",
+ "CloudFront-Viewer-Country": "US",
+ "Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com",
+ "Upgrade-Insecure-Requests": "1",
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
+ "Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)",
+ "X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==",
+ "X-Forwarded-For": "192.168.100.1, 192.168.1.1",
+ "X-Forwarded-Port": "443",
+ "X-Forwarded-Proto": "https"
+ },
+ "pathParameters": {
+ "proxy": "hello"
+ },
+ "requestContext": {
+ "accountId": "123456789012",
+ "resourceId": "us4z18",
+ "stage": "test",
+ "requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
+ "identity": {
+ "cognitoIdentityPoolId": "",
+ "accountId": "",
+ "cognitoIdentityId": "",
+ "caller": "",
+ "apiKey": "",
+ "sourceIp": "192.168.100.1",
+ "cognitoAuthenticationType": "",
+ "cognitoAuthenticationProvider": "",
+ "userArn": "",
+ "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
+ "user": ""
+ },
+ "resourcePath": "/{proxy+}",
+ "httpMethod": "GET",
+ "apiId": "wt6mne2s9k"
+ },
+ "resource": "/{proxy+}",
+ "httpMethod": "GET",
+ "queryStringParameters": {
+ "to_email": "[email protected]"
+ },
+ "stageVariables": {
+ "stageVarName": "stageVarValue"
+ }
+}
diff --git a/serverless/src/main.rs b/serverless/src/main.rs
new file mode 100644
index 00000000..0ce06d34
--- /dev/null
+++ b/serverless/src/main.rs
@@ -0,0 +1,46 @@
+extern crate lambda_http;
+extern crate lambda_runtime;
+extern crate lettre;
+extern crate serde_json;
+
+use check_if_email_exists_core::email_exists;
+use lambda_http::{lambda, IntoResponse, Request, RequestExt};
+use lambda_runtime::{error::HandlerError, Context};
+use lettre::EmailAddress;
+use serde_json::json;
+use std::borrow::Cow;
+use std::str::FromStr;
+
+/// Return HTTP response with error when there's one
+macro_rules! try_or_return (
+ ($res: expr) => ({
+ match $res {
+ Ok(value) => value,
+ Err(err) => {
+ return Ok(json!({ "error": format!("{:?}", err) }));
+ }
+ }
+ })
+);
+
+fn main() {
+ lambda!(handler)
+}
+
+fn handler(request: Request, _: Context) -> Result<impl IntoResponse, HandlerError> {
+ let query_params = request.query_string_parameters();
+ if let Some(to_email) = query_params.get("to_email") {
+ let from_email = query_params
+ .get("from_email")
+ .unwrap_or(&Cow::Borrowed("[email protected]"));
+
+ let from_email = try_or_return!(EmailAddress::from_str(from_email));
+ let to_email = try_or_return!(EmailAddress::from_str(to_email));
+
+ let exists = try_or_return!(email_exists(&from_email, &to_email));
+
+ Ok(json!({ "message": exists }))
+ } else {
+ Ok(json!({ "error": "`to_email` is a required query param" }))
+ }
+}
diff --git a/src/bin/main.rs b/src/bin/main.rs
deleted file mode 100644
index 39115b61..00000000
--- a/src/bin/main.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-extern crate env_logger;
-#[macro_use]
-extern crate clap;
-extern crate check_if_email_exists;
-
-use check_if_email_exists::email_exists;
-use clap::App;
-
-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_EMAIL").unwrap_or("[email protected]");
- // Calling .unwrap() is safe here because "TO" is required
- let to_email = matches.value_of("TO_EMAIL").unwrap();
-
- match email_exists(from_email, to_email) {
- Some(value) => println!("{}", value),
- None => println!("Can't check if email exists, see logs for more info"),
- }
-}