summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <git@iximeow.net>2022-12-26 00:50:58 +0000
committeriximeow <git@iximeow.net>2022-12-26 00:50:58 +0000
commit567081631e846b241039a112a11ead101a0aefc8 (patch)
tree084df73bf4486e12bb40153ecb3d81bd521438e5 /src
parent7e84420dfe659494318630863ff97a75b0ad32ff (diff)
support sending emails when notifying about build states
Diffstat (limited to 'src')
-rw-r--r--src/notifier.rs49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/notifier.rs b/src/notifier.rs
index 3ccda47..f9d6084 100644
--- a/src/notifier.rs
+++ b/src/notifier.rs
@@ -127,7 +127,54 @@ impl RemoteNotifier {
}
}
NotifierConfig::Email { username, password, mailserver, from, to } => {
- panic!("should send an email saying that a job is now pending for `sha`")
+ eprintln!("[.] emailing {} for job {} via {}", state, &self.remote_path, mailserver);
+
+ let subject = format!("{}: job for {}", state, &self.remote_path);
+
+ let body = format!("{}", subject);
+
+ // TODO: when ci.butactuallyin.space has valid certs again, ... fix this.
+ let tls = TlsParametersBuilder::new(mailserver.to_string())
+ .dangerous_accept_invalid_certs(true)
+ .build()
+ .unwrap();
+
+ let mut mailer = SmtpConnection::connect(
+ mailserver,
+ Some(Duration::from_millis(5000)),
+ &ClientId::Domain("ci.butactuallyin.space".to_string()),
+ None,
+ None,
+ ).unwrap();
+
+ mailer.starttls(
+ &tls,
+ &ClientId::Domain("ci.butactuallyin.space".to_string()),
+ ).unwrap();
+
+ let resp = mailer.auth(
+ &[Mechanism::Plain, Mechanism::Login],
+ &Credentials::new(username.to_owned(), password.to_owned())
+ ).unwrap();
+ assert!(resp.is_positive());
+
+ let email = Message::builder()
+ .from(from.parse().unwrap())
+ .to(to.parse().unwrap())
+ .subject(&subject)
+ .body(body)
+ .unwrap();
+
+ match mailer.send(email.envelope(), &email.formatted()) {
+ Ok(_) => {
+ eprintln!("[+] notified {}@{}", username, mailserver);
+ Ok(())
+ }
+ Err(e) => {
+ eprintln!("[-] could not send email: {:?}", e);
+ Err(e.to_string())
+ }
+ }
}
}
}