24 lines
751 B
Rust
24 lines
751 B
Rust
use lettre::{message::header::ContentType, Message, SmtpTransport, Transport};
|
|
|
|
fn main() {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
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")
|
|
.header(ContentType::TEXT_PLAIN)
|
|
.body(String::from("Be happy!"))
|
|
.unwrap();
|
|
|
|
// Open a local connection on port 25
|
|
let mailer = SmtpTransport::unencrypted_localhost();
|
|
|
|
// Send the email
|
|
match mailer.send(&email) {
|
|
Ok(_) => println!("Email sent successfully!"),
|
|
Err(e) => panic!("Could not send email: {e:?}"),
|
|
}
|
|
}
|