34 lines
908 B
Rust
34 lines
908 B
Rust
use lettre::{transport::smtp::authentication::Credentials, 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("Be happy!")
|
|
.unwrap();
|
|
|
|
let creds = Credentials::new(
|
|
"example_username".to_string(),
|
|
"example_password".to_string(),
|
|
);
|
|
|
|
// Open a remote connection to gmail
|
|
let mailer = SmtpTransport::relay("smtp.gmail.com")
|
|
.unwrap()
|
|
.credentials(creds)
|
|
.build();
|
|
|
|
// Send the email
|
|
let result = mailer.send(&email);
|
|
|
|
if result.is_ok() {
|
|
println!("Email sent");
|
|
} else {
|
|
println!("Could not send email: {:?}", result);
|
|
}
|
|
|
|
assert!(result.is_ok());
|
|
}
|