use lettre::transport::smtp::authentication::Credentials;
use lettre::transport::smtp::SmtpTransport;
use lettre::{Message, Transport};
fn main() {
let email = Message::builder()
.from("NoBody <from@email.ch>".parse().unwrap())
.reply_to("Yuin <from@email.ch>".parse().unwrap())
.to("Hei <to@email.ch>".parse().unwrap())
.subject("Happy new year")
.body(String::from("Be happy!"))
.unwrap();
let creds = Credentials::new("your_username".to_string(), "very_secret_password".to_string());
// Open a remote connection to gmail
let mailer = SmtpTransport::starttls_relay("my_start_tls_relay.ch")
.unwrap()
.credentials(creds)
.build();
// Send the email
match mailer.send(&email) {
Ok(_) => println!("Email sent successfully!"),
Err(e) => panic!("Could not send email: {:?}", e),
}
}
Watch out - I'm having an email server configured using port 587 and STARTTLS. Using the same lettre version as you mentioned - compiled with Rust 1.53.0.
Note: it is just the example mentioned on github https://github.com/lettre/lettre - with some small adaptions.