Skip to content

Commit

Permalink
add lettre example
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jan 11, 2021
1 parent 83d1551 commit 41e51d7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lettre_email1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
use lettre::{
smtp::{error::Error, response::Response},
ClientSecurity, SendableEmail, SmtpClient, SmtpTransport, Transport,
};
use lettre_email::Email;

fn main() {
println!("Hello, world!");
let email: Email = Email::builder()
.to(("m@bouzuya.net", "bouzuya"))
.from("m@bouzuya.net")
.subject("SUBJECT")
.text("Hello lettre.")
.build()
.unwrap();
let sendable_email: SendableEmail = email.into();

// let smtp_client = SmtpClient::new_unencrypted_localhost().unwrap();
let smtp_client: SmtpClient =
SmtpClient::new(("localhost", 3025), ClientSecurity::None).unwrap();
let mut smtp_transport: SmtpTransport = smtp_client.transport();
let result: Result<Response, Error> = smtp_transport.send(sendable_email);
match result {
Ok(resp) => println!("Ok: {:?}", resp),
Err(err) => println!("Err: {:?}", err),
}
}

0 comments on commit 41e51d7

Please sign in to comment.