diff options
author | iximeow <git@iximeow.net> | 2022-12-26 00:50:58 +0000 |
---|---|---|
committer | iximeow <git@iximeow.net> | 2022-12-26 00:50:58 +0000 |
commit | 567081631e846b241039a112a11ead101a0aefc8 (patch) | |
tree | 084df73bf4486e12bb40153ecb3d81bd521438e5 /src/notifier.rs | |
parent | 7e84420dfe659494318630863ff97a75b0ad32ff (diff) |
support sending emails when notifying about build states
Diffstat (limited to 'src/notifier.rs')
-rw-r--r-- | src/notifier.rs | 49 |
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()) + } + } } } } |