summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2020-12-04 21:43:45 +0100
committerSanto Cariotti <santo@dcariotti.me>2020-12-04 21:43:45 +0100
commitfcd222a0fc8731bb34e46dd5f7948a7f84156100 (patch)
treeec701a4d8a22fdcc38f70003c2cb4358bd2290f8
parentcc2aa68d4e9ec4ad0d8cd7633f4a46469c177606 (diff)
chore: "From" email setted by env
-rw-r--r--README.md3
-rw-r--r--src/main.rs16
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 <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))