This commit is contained in:
Paolo Barbolini
2025-05-02 05:47:53 +02:00
parent abc8cdf789
commit b7482f0232
2 changed files with 15 additions and 7 deletions

View File

@@ -4,7 +4,10 @@ use lettre::{
message::header::ContentType,
transport::smtp::{
authentication::Credentials,
client::{tls, Tls},
client::{
tls::{native_tls::Certificate, NativeTls, TlsParametersBuilder},
Tls,
},
},
Message, SmtpTransport, Transport,
};
@@ -23,8 +26,8 @@ fn main() {
// Use a custom certificate stored on disk to securely verify the server's certificate
let pem_cert = fs::read("certificate.pem").unwrap();
let cert = tls::native_tls::Certificate::from_pem(&pem_cert).unwrap();
let tls = tls::TlsParametersBuilder::<tls::NativeTls>::new("smtp.server.com".to_owned())
let cert = Certificate::from_pem(&pem_cert).unwrap();
let tls = TlsParametersBuilder::<NativeTls>::new("smtp.server.com".to_owned())
.add_root_certificate(cert)
.build_legacy()
.unwrap();

View File

@@ -107,7 +107,10 @@
//!
//! use lettre::{
//! message::header::ContentType,
//! transport::smtp::client::{Certificate, Tls, TlsParameters},
//! transport::smtp::client::{
//! tls::{native_tls::Certificate, NativeTls, TlsParametersBuilder},
//! Tls,
//! },
//! Message, SmtpTransport, Transport,
//! };
//!
@@ -122,9 +125,11 @@
//! // Custom TLS configuration - Use a self signed certificate
//! let cert = fs::read("self-signed.crt")?;
//! let cert = Certificate::from_pem(&cert)?;
//! let tls = TlsParameters::builder(/* TLS SNI value */ "smtp.example.com".to_owned())
//! .add_root_certificate(cert)
//! .build()?;
//! let tls = TlsParametersBuilder::<NativeTls>::new(
//! /* TLS SNI value */ "smtp.example.com".to_owned(),
//! )
//! .add_root_certificate(cert)
//! .build_legacy()?;
//!
//! // Create the SMTPS transport
//! let sender = SmtpTransport::relay("smtp.example.com")?