* Update dependencies (#386) * Update dependencies and set MSRV to 1.40 * update hyperx * Use display instead of description for errors * Make hostname an optional feature * Envelope from headers * Update hyperx to 1.0 * rename builder to message * Cleanup and make Transport send Messages * Update rustls from 0.16 to 0.17 * Move transports into a common folder * Merge imports from same crate * Add message creation example to the site * Hide "extern crate" in doc examples * Add References and In-Reply-To methods * Add message-id header * Add blog posts and improve doc examples
36 lines
936 B
Rust
36 lines
936 B
Rust
extern crate lettre;
|
|
|
|
use lettre::{transport::smtp::authentication::Credentials, Message, SmtpClient, 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 mut mailer = SmtpClient::new_simple("smtp.gmail.com")
|
|
.unwrap()
|
|
.credentials(creds)
|
|
.transport();
|
|
|
|
// 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());
|
|
}
|