Help with Lettre! vm issue

i made a email function using Lettre which adds attachments and certain body of functions if required.

It is working great on 3 computers but in my VM (win10) it has the following error: Lettre::transport:smpt:ERROR {kind: Connection, source: Failure (OS {code: -2146762487, kind: uncategorized, message: "A certificate chain processed, but terminated in a root sertificate which is not trusted by the trust provider })} Os {code: 2, kind: notfound, Message: "the system cannot find the file specified."}..

its a certificate issue but cant see what is the best way out.

The vm is barebones and new. any guidance is appreciated..

Here is my current code:

use lettre::message::SinglePart;

use lettre::{Message, SmtpTransport, Transport};

use lettre::transport::smtp::authentication::Credentials;

use lettre::message::{Attachment, header::ContentType};

pub fn send_email(log_file_path: &str, use_system_info: bool) -> Result<(), Box<dyn std::error::Error>> {

    let email_address: &str = "x@gmail.com"; // looking to make this stronger and not hardwired
    let password: &str = "gmailapppassword";
   
    let system_info = get_system_info();
    let first_e = first_email();

    let email_body = if use_system_info {
        format!("See attached.\n\nSystem Information:\n{}", system_info)
    } else {
        format!("See attached.\n\n{}", first_e)
    };
   
    let filename = String::from("File.txt");
    let filebody = fs::read (log_file_path)?;
    let content_type = ContentType::parse("text/plain").unwrap();  
    let log_attachment = Attachment::new(filename).body(filebody, content_type);
     //
    // original
     //let log_attachment = SinglePart::builder()
     //.header(ContentType::TEXT_PLAIN)
     //.body(fs::read(log_file_path)?); 
     //
    let email = Message::builder()
                 .from("x@gmail.com".parse().unwrap())
                 .to("x@gmail.com".parse().unwrap())
                 .subject("Classified")
                 .multipart(lettre::message::MultiPart::mixed()
                            .singlepart(SinglePart::builder()
                              .header(ContentType::TEXT_PLAIN)
                              .body(String::from (email_body))      
                                )
                              .singlepart(log_attachment)
                    
                        ).unwrap();
                        
    let creds = Credentials::new(email_address.to_string(), password.to_string());
    let mailer = SmtpTransport::relay("smtp.gmail.com")
        .unwrap()
        .credentials(creds)
        .build();
    

        std::thread::sleep(std::time::Duration::from_secs(2));
        match mailer.send(&email)
         {
            Ok(_) => {
                    Ok(())
            }
            Err(e) => Err(Box::new(e)),
        }
}

Lettre seems to support different TLS libraries via dependency features native-tls, rustls-tls and boring-tls. Which one you are using will be key to fix your certificate issue.

Thank you, i am leaning towards rustls-tls as it can be contained within my program without depending on external libraries.

Ill look into its implementation and if i have to change to native later on ill advise.

Thanks!

i would prefer to just use the existing code as making the "native" and "rust-tls" changes seems to be breaking my function, especially with the attachment.

Is there a way to have the "danger_accept_invalid_certs" or something?

examples welcome.

Just sharing that it was a certificates issue on my VM nothing to do with the code mentioned above..
Closing this thread now.. Also you have a working email sending (gmail app password required) with attachments..

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.