0

I am not very good in rust, using version 1.32.0 of rustc and cargo to control a heating system, which works very fine. Now I try to integrate a simple smtp function, to get information about bad system states via mail. I tried "lettre" from version 0.4 to 10.0 , but all the time I get many errors "use of unstable library feature" concerning "'split_ascii_whitespace', 'try_from', 'alloc', 'maybe_uninit' ...". "lettre" ends in "Could not compile cc". With "mail-smtp" I had similar problems. Is there any solution for this, how can I work with an older version of rustc and cargo, which I need for my control software, without crashing by using new crates?

I used the folllowing code from https://github.com/lettre/lettre#readme:

Cargo.toml:

[dependencies]
lettre = "0.10.0-beta.3"  # here I tried also "0.9" down to "0.4"

main.rs:

extern crate lettre;

fn main() {

use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};

let email = Message::builder()
    .from("NoBody <nobody@domain.tld>".parse().unwrap())
    .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
    .to("Hei <hei@domain.tld>".parse().unwrap())
    .subject("Happy new year")
    .body(String::from("Be happy!"))
    .unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());

// Open a remote connection to gmail
let mailer = SmtpTransport::relay("smtp.gmail.com")
    .unwrap()
    .credentials(creds)
    .build();

// Send the email
match mailer.send(&email) {
    Ok(_) => println!("Email sent successfully!"),
    Err(e) => panic!("Could not send email: {:?}", e),
}
}
hig
  • 17
  • 1
  • 1
    Your version of Rust is relatively old. The dependency you are attempting to use requires features stabilized in a newer version of Rust. Upgrade Rust. – Shepmaster May 04 '21 at 17:12
  • 2
    *how can I work with an older version of rustc and cargo, which I need for my control software* — 99% of the time, this is not the case. You should be able to upgrade Rust and continue compiling code that previously compiled. A **lot** of effort goes into ensuring that. – Shepmaster May 04 '21 at 17:13
  • 1
    This will not work without updating the compiler since the project is using features that were stabilized in those versions. As noted above. – Skarlett May 04 '21 at 17:53
  • Thanks a lot for the answers. I now realized that lettre only works with rust higher than 1.46. Some months ago I did upgrade rust for another purpose - and could not compile my control software any more (many unstable features). It took me a lot of time to fall back to the old version 1.32.0. Maybe someone knows a simple smtp-mailer, which works with this old version? Just need to send simple status mails. – hig May 06 '21 at 14:48
  • You encouraged me to try again a Rust upgrade -thanks. This time, it worked (I kind of fell into it the last time) with some little problems. The compiler threw 3 warnings and 3 errors with my old code for Rust 1.32.0, but the explanations were helpful to fix it. Now I'm free to use newer crates and sent already my first email with Rust Thank you - problem solved. – hig May 07 '21 at 12:18

0 Answers0