Files
advotracker/advotracker_client/examples/email_test.rs
2021-05-23 14:36:35 +02:00

48 lines
1.6 KiB
Rust

// SPDX-License-Identifier: (0BSD or MIT)
/*
* advotracker - Hotline tackingtool for Advocats
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
*/
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),
}
}