feat(transport-smtp): Upgrade to 0.2 version of native-tls crate

This commit is contained in:
tyranron
2018-07-08 09:42:58 +03:00
parent e225afbec2
commit 644b1e59b0
3 changed files with 54 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ is-it-maintained-open-issues = { repository = "lettre/lettre" }
log = "^0.4"
nom = { version = "^3.2", optional = true }
bufstream = { version = "^0.1", optional = true }
native-tls = { version = "^0.1", optional = true }
native-tls = { version = "^0.2", optional = true }
base64 = { version = "^0.9", optional = true }
hostname = { version = "^0.1", optional = true }
serde = { version = "^1.0", optional = true }

View File

@@ -125,8 +125,8 @@ impl SmtpClient {
/// Creates an encrypted transport over submissions port, using the provided domain
/// to validate TLS certificates.
pub fn new_simple(domain: &str) -> Result<SmtpClient, Error> {
let mut tls_builder = TlsConnector::builder()?;
tls_builder.supported_protocols(DEFAULT_TLS_PROTOCOLS)?;
let mut tls_builder = TlsConnector::builder();
tls_builder.min_protocol_version(Some(DEFAULT_TLS_PROTOCOLS[0]));
let tls_parameters =
ClientTlsParameters::new(domain.to_string(), tls_builder.build().unwrap());

View File

@@ -96,6 +96,57 @@ fn main() {
}
```
You can specify custom TLS settings:
```rust,no_run
extern crate native_tls;
extern crate lettre;
extern crate lettre_email;
use lettre::{
ClientSecurity, ClientTlsParameters, EmailAddress, Envelope,
SendableEmail, SmtpClient, Transport,
};
use lettre::smtp::authentication::{Credentials, Mechanism};
use lettre::smtp::ConnectionReuseParameters;
use native_tls::{Protocol, TlsConnector};
fn main() {
let email = SendableEmail::new(
Envelope::new(
Some(EmailAddress::new("user@localhost".to_string()).unwrap()),
vec![EmailAddress::new("root@localhost".to_string()).unwrap()],
).unwrap(),
"message_id".to_string(),
"Hello world".to_string().into_bytes(),
);
let mut tls_builder = TlsConnector::builder();
tls_builder.min_protocol_version(Some(Protocol::Tlsv10));
let tls_parameters =
ClientTlsParameters::new(
"smtp.example.com".to_string(),
tls_builder.build().unwrap()
);
let mut mailer = SmtpClient::new(
("smtp.example.com", 465), ClientSecurity::Wrapper(tls_parameters)
).unwrap()
.authentication_mechanism(Mechanism::Login)
.credentials(Credentials::new(
"example_username".to_string(), "example_password".to_string()
))
.connection_reuse(ConnectionReuseParameters::ReuseUnlimited)
.transport();
let result = mailer.send(email);
assert!(result.is_ok());
mailer.close();
}
```
#### Lower level
You can also send commands, here is a simple email transaction without