From 1936211f8e8cfae31ec8ad430254291537d5f3c2 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sun, 19 Nov 2017 22:21:13 +0100 Subject: [PATCH] feat(transport-smtp): Use hostname as clientid when available --- lettre/Cargo.toml | 3 ++- lettre/src/lib.rs | 2 ++ lettre/src/smtp/mod.rs | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lettre/Cargo.toml b/lettre/Cargo.toml index f8afa38..768a88d 100644 --- a/lettre/Cargo.toml +++ b/lettre/Cargo.toml @@ -21,6 +21,7 @@ bufstream = { version = "^0.1", optional = true } native-tls = { version = "^0.1", optional = true } base64 = { version = "^0.8", optional = true } hex = { version = "^0.3", optional = true } +hostname = { version = "^0.1", optional = true } rust-crypto = { version = "^0.2", optional = true } serde = { version = "^1.0", optional = true } serde_json = { version = "^1.0", optional = true } @@ -35,7 +36,7 @@ unstable = [] serde-impls = ["serde", "serde_derive"] file-transport = ["serde-impls", "serde_json"] crammd5-auth = ["rust-crypto", "hex"] -smtp-transport = ["bufstream", "native-tls", "base64", "nom"] +smtp-transport = ["bufstream", "native-tls", "base64", "nom", "hostname"] sendmail-transport = [] [[example]] diff --git a/lettre/src/lib.rs b/lettre/src/lib.rs index bf4a9b5..2d31d7a 100644 --- a/lettre/src/lib.rs +++ b/lettre/src/lib.rs @@ -19,6 +19,8 @@ extern crate base64; extern crate bufstream; #[cfg(feature = "smtp-transport")] extern crate native_tls; +#[cfg(feature = "smtp-transport")] +extern crate hostname; #[cfg(feature = "file-transport")] extern crate serde_json; #[cfg(feature = "serde-impls")] diff --git a/lettre/src/smtp/mod.rs b/lettre/src/smtp/mod.rs index 6721d77..2cbf35e 100644 --- a/lettre/src/smtp/mod.rs +++ b/lettre/src/smtp/mod.rs @@ -106,6 +106,7 @@ use EmailTransport; use SendableEmail; use native_tls::TlsConnector; +use hostname::get_hostname; use smtp::authentication::{Credentials, DEFAULT_ENCRYPTED_MECHANISMS, DEFAULT_UNENCRYPTED_MECHANISMS, Mechanism}; use smtp::client::Client; @@ -224,7 +225,7 @@ impl SmtpTransportBuilder { smtp_utf8: false, credentials: None, connection_reuse: ConnectionReuseParameters::NoReuse, - hello_name: ClientId::Domain("localhost".to_string()), + hello_name: ClientId::Domain(get_hostname().unwrap_or("localhost".to_string())), authentication_mechanism: None, timeout: Some(Duration::new(60, 0)), })