Last active
September 1, 2024 02:57
-
-
Save zwpaper/bca2917433c56c4b541397f4a6ac6516 to your computer and use it in GitHub Desktop.
Revisions
-
zwpaper revised this gist
Sep 1, 2024 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,12 +20,13 @@ fn main() { .unwrap(); let cert = Certificate::from_pem(&std::fs::read("./smtp.crt").unwrap()) .unwrap(); println!("cert: {:?}", cert); let tls_parameters = TlsParameters::builder("smtp.example.com".into()) .add_root_certificate(cert) // .dangerous_accept_invalid_certs(true) .build() .unwrap(); @@ -37,7 +38,7 @@ fn main() { // Create the SMTP transport with STARTTLS let mailer = SmtpTransport::builder_dangerous("smtp.example.com") .port(1025) .tls(Tls::Required(tls_parameters)) .credentials(creds) .build(); @@ -47,4 +48,4 @@ fn main() { Ok(_) => println!("Email sent successfully!"), Err(e) => println!("Could not send email: {:?}", e), } } -
zwpaper revised this gist
Aug 31, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ fn main() { let tls_parameters = TlsParameters::builder("smtp.example.com".into()) .add_root_certificate(cert) // .dangerous_accept_invalid_certs(true) .build() .unwrap(); -
zwpaper created this gist
Aug 31, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ use lettre::transport::smtp::SmtpTransport; use lettre::{ message::Message, transport::smtp::{ authentication::Credentials, client::{Certificate, Tls, TlsParameters}, }, Transport, }; fn main() { // Create the email message let email = Message::builder() .from("[email protected]".parse().unwrap()) .to("[email protected]".parse().unwrap()) .subject("Hello from Rust!") .body(String::from( "This is a test email sent using Rust with STARTTLS.", )) .unwrap(); let cert = Certificate::from_pem(&std::fs::read("smtp.crt").unwrap()) .unwrap(); let tls_parameters = TlsParameters::builder("smtp.example.com".into()) .add_root_certificate(cert) .build() .unwrap(); // SMTP credentials let creds = Credentials::new( "[email protected]".to_string(), "your-password".to_string(), ); // Create the SMTP transport with STARTTLS let mailer = SmtpTransport::builder_dangerous("smtp.example.com") .port(587) .tls(Tls::Required(tls_parameters)) .credentials(creds) .build(); // Send the email match mailer.send(&email) { Ok(_) => println!("Email sent successfully!"), Err(e) => println!("Could not send email: {:?}", e), } }