From fcd222a0fc8731bb34e46dd5f7948a7f84156100 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 4 Dec 2020 21:43:45 +0100 Subject: chore: "From" email setted by env --- README.md | 3 ++- src/main.rs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d4a048e..acc4c45 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -# rsanta - make your Secret Santa +# rsanta - Make secret santa with your friends You must set environments variables for smtp: ``` +export NAME=nameofemail export EMAIL=youremail@tld.com export PASSWORD=passsword export HOST=smtp_host diff --git a/src/main.rs b/src/main.rs index b1f36da..a6db4e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,9 +38,17 @@ fn main() { .expect("Error occurs reading this file") .to_string(); + let config_name; let config_email; let config_password; let host; + match env::var("NAME") { + Ok(v) => config_name = v.to_string(), + Err(_) => { + dbg!("Use default name!"); + config_name = "Santa Claus".to_string(); + } + } match env::var("EMAIL") { Ok(v) => config_email = v.to_string(), Err(e) => panic!("Must provide EMAIL: {}", e), @@ -76,7 +84,7 @@ fn main() { emails.push(email.to_string()); } - let creds = Credentials::new(config_email, config_password); + let creds = Credentials::new(config_email.to_string(), config_password); let mailer = SmtpTransport::relay(&host) .unwrap() @@ -91,7 +99,11 @@ fn main() { && !done.iter().any(|v| v == gift_to) { let mail = Message::builder() - .from("Santo Cariotti ".parse().unwrap()) + .from( + format!("{} <{}>", config_name, config_email) + .parse() + .unwrap(), + ) .to(format!("{} <{}>", name, email).parse().unwrap()) .subject("Secret Santa!") .body(format!("You're the Secret Santa of:\n{}", name)) -- cgit v1.2.3-18-g5258