Skip to content

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

fix: Use TLS when available (#964)

dblanovschiaed11d2e15b6
diff --git a/Cargo.lock b/Cargo.lock
index 28aefc48..fd7fab91 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -309,6 +309,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
name = "check-if-email-exists"
version = "0.8.24"
dependencies = [
+ "async-native-tls",
"async-smtp",
"async-std",
"async-std-resolver",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 5a10d1de..03d663da 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -17,6 +17,7 @@ appveyor = { repository = "reacherhq/check-if-email-exists", service = "github"
travis-ci = { repository = "reacherhq/check-if-email-exists", service = "github" }
[dependencies]
+async-native-tls = "0.3.3"
async-smtp = { version = "0.4.0", features = ["socks5"] }
async-std = "1.10.0"
async-std-resolver = "0.20.3"
diff --git a/core/src/smtp/mod.rs b/core/src/smtp/mod.rs
index 6a70fe62..1dd3a44a 100644
--- a/core/src/smtp/mod.rs
+++ b/core/src/smtp/mod.rs
@@ -18,12 +18,13 @@ mod yahoo;
use super::util::{constants::LOG_TARGET, input_output::CheckEmailInput};
use crate::util::ser_with_display::ser_with_display;
+use async_native_tls::TlsConnector;
use async_smtp::{
smtp::{
client::net::NetworkStream, commands::*, error::Error as AsyncSmtpError,
extension::ClientId,
},
- ClientSecurity, EmailAddress, SmtpClient, SmtpTransport,
+ ClientSecurity, ClientTlsParameters, EmailAddress, SmtpClient, SmtpTransport,
};
use async_std::future;
use fast_socks5::{
@@ -125,13 +126,20 @@ async fn connect_to_host(
port: u16,
input: &CheckEmailInput,
) -> Result<SmtpTransport, SmtpError> {
- let mut smtp_client =
- SmtpClient::with_security((host.to_utf8().as_ref(), port), ClientSecurity::None)
- .await?
- // FIXME Do not clone?
- .hello_name(ClientId::Domain(input.hello_name.clone()))
- .timeout(Some(Duration::new(30, 0))) // Set timeout to 30s
- .into_transport();
+ let security = {
+ let host_string = host.to_utf8();
+ let host_str = host_string.trim_end_matches('.'); // hostname verification fails if it ends with '.'
+ ClientSecurity::Opportunistic(ClientTlsParameters::new(
+ host_str.to_string(),
+ TlsConnector::new().use_sni(true),
+ ))
+ };
+ let mut smtp_client = SmtpClient::with_security((host.to_utf8().as_ref(), port), security)
+ .await?
+ // FIXME Do not clone?
+ .hello_name(ClientId::Domain(input.hello_name.clone()))
+ .timeout(Some(Duration::new(30, 0))) // Set timeout to 30s
+ .into_transport();
// Connect to the host. If the proxy argument is set, use it.
log::debug!(target: LOG_TARGET, "Connecting to {}:{}", host, port);