23 lines
687 B
Rust
23 lines
687 B
Rust
use lettre::{Message, SmtpTransport, Transport};
|
|
|
|
fn main() {
|
|
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();
|
|
|
|
// Open a remote connection to gmail
|
|
let mailer = SmtpTransport::builder_dangerous("localhost")
|
|
.port(7778)
|
|
.build();
|
|
|
|
// Send the email
|
|
match mailer.send(&email) {
|
|
Ok(_) => println!("Email sent successfully!"),
|
|
Err(e) => panic!("Could not send email: {:?}", e),
|
|
}
|
|
}
|