Files
advotracker/crates/advotracker/examples/email_test.rs
Ralf Zerres 4c88167bef advotracker: restructure project using crate tree
* advotracker: the framework crate
* crate/advotrackerdb: crate implementing the database backend
* crate/advotrackerd: the backend daemon
* crate/adovtracker: the application (CLI and GUI)

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-03-08 04:32:11 +01:00

41 lines
1.4 KiB
Rust

use lettre::{
transport::smtp::authentication::Credentials,
Message, SmtpTransport, Transport,
};
fn main() {
let email = Message::builder()
.from("Info <info@networkx.de>".parse().unwrap())
.reply_to("Support <support@networkx.de>".parse().unwrap())
.to("Ralf Zerres <ralf.zerres@networkx.de>".parse().unwrap())
.subject("Eine advotracker eMail")
.body("Eine neue advotracker eMail!".to_string())
.unwrap();
// Create credential for remote authentication (username, password)
//let creds = Credentials::new("ralf.zerres@networkx.de".to_string(), "dekifjgh".to_string());
let creds = Credentials::new("ralf.zerres.de@gmail.com".to_string(), "20jacara03".to_string());
// Open a remote connection to relay server
//let mailer = SmtpTransport::relay("nwxex.networkx.de")
let mailer = SmtpTransport::relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.build();
// Open a remote connection to gmail using STARTTLS
// let mailer = SmtpTransport::starttls_relay("nwxex.networkx.de")
// .unwrap()
// .credentials(creds)
// .build();
// Open a local connection on port 25
//let mailer = SmtpTransport::unencrypted_localhost();
// Send the email
match mailer.send(&email) {
Ok(_) => println!("Email sent successfully!"),
Err(e) => panic!("Could not send email: {:?}", e),
}
}