diff options
author | Santo Cariotti <santo@dcariotti.me> | 2020-12-04 21:43:45 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2020-12-04 21:43:45 +0100 |
commit | fcd222a0fc8731bb34e46dd5f7948a7f84156100 (patch) | |
tree | ec701a4d8a22fdcc38f70003c2cb4358bd2290f8 /src | |
parent | cc2aa68d4e9ec4ad0d8cd7633f4a46469c177606 (diff) |
chore: "From" email setted by env
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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 <santo@dcariotti.me>".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)) |