1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/// The `Notify` trait represents the ability to send an alert message.
///
/// # Example
///
/// ```
/// use lettre::{
/// Address,
/// message::Mailbox,
/// Message,
/// transport::smtp::authentication::Credentials,
/// SmtpTransport,
/// Transport
/// };
///
/// use log::info;
/// use gargoyle::Notify;
///
/// pub struct Email {
/// pub from: Mailbox,
/// pub to: Mailbox,
/// pub relay: String,
/// pub smtp_username: String,
/// pub smtp_password: String,
/// }
///
/// impl Notify for Email {
/// fn send(&self, msg: &str, diagnostic: Option<String>) -> Result<(), String> {
/// let email = Message::builder()
/// .from(self.from.clone())
/// .to(self.to.clone())
/// .subject(msg)
/// .body(diagnostic.unwrap_or(msg.to_string()))
/// .map_err(|e| format!("Failed to build a message: {e}"))?;
///
/// let creds = Credentials::new(self.smtp_username.clone(), self.smtp_password.clone());
///
/// let mailer = SmtpTransport::relay(&self.relay)
/// .map_err(|e| format!("Failed to create a mailer: {e}"))?
/// .credentials(creds)
/// .build();
///
/// info!("Sending email notification from {} to {} via {}.", self.from, self.to, self.relay);
/// match mailer.send(&email) {
/// Ok(_) => Ok(()),
/// Err(e) => Err(format!("Failed to send email: {e}")),
/// }
/// }
/// }
/// ```