use lettre::message::{header, MultiPart, SinglePart}; use lettre::{FileTransport, Message, Transport}; fn main() { // The html we want to send. let html = r#" Hello from Lettre!

Hello from Lettre!

A mailer library for Rust

"#; // Build the message. let email = Message::builder() .from("NoBody ".parse().unwrap()) .to("Hei ".parse().unwrap()) .subject("Hello from Lettre!") .multipart( MultiPart::alternative() // This is composed of two parts. .singlepart( SinglePart::builder() .header(header::ContentType( "text/plain; charset=utf8".parse().unwrap(), )) .body(String::from("Hello from Lettre! A mailer library for Rust")), // Every message should have a plain text fallback. ) .singlepart( SinglePart::builder() .header(header::ContentType( "text/html; charset=utf8".parse().unwrap(), )) .body(String::from(html)), ), ) .expect("failed to build email"); // Create our mailer. Please see the other examples for creating SMTP mailers. // The path given here must exist on the filesystem. let mailer = FileTransport::new("./"); // Store the message when you're ready. mailer.send(&email).expect("failed to deliver message"); }