use lettre::{ message::header::ContentType, transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncStd1Executor, AsyncTransport, Message, }; #[async_std::main] async fn main() { tracing_subscriber::fmt::init(); let email = Message::builder() .from("NoBody ".parse().unwrap()) .reply_to("Yuin ".parse().unwrap()) .to("Hei ".parse().unwrap()) .subject("Happy new async year") .header(ContentType::TEXT_PLAIN) .body(String::from("Be happy with async!")) .unwrap(); let creds = Credentials::new("smtp_username".to_owned(), "smtp_password".to_owned()); // Open a remote connection to gmail let mailer: AsyncSmtpTransport = AsyncSmtpTransport::::relay("smtp.gmail.com") .unwrap() .credentials(creds) .build(); // Send the email match mailer.send(email).await { Ok(_) => println!("Email sent successfully!"), Err(e) => panic!("Could not send email: {e:?}"), } }