Quelques corrections

This commit is contained in:
Rémi BERTHO 2023-06-15 22:03:45 +02:00
parent b912f9140e
commit fc65a4069d
Signed by: dalan
GPG key ID: EE3B917931C07B64
4 changed files with 472 additions and 391 deletions

814
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
lettre = "0.10" lettre = "0.10"
toml = "0.5" toml = "0.7"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
log = "0.4" log = "0.4"
simplelog = "0.12" simplelog = "0.12"

View file

@ -4,4 +4,5 @@
* [ ] Rustfmt * [ ] Rustfmt
* [ ] Logs tournant * [ ] Logs tournant
* [ ] Fonction check asychrone * [ ] Fonction check asychrone
* [ ] Utilisation de l[API Gandi](https://api.gandi.net/docs/livedns) via [restson](https://crates.io/crates/restson) * [ ] Utilisation de https://crates.io/crates/public-ip ?
* [ ] Test automatique avec mailin-embedded

View file

@ -199,34 +199,36 @@ impl Tester {
fn send_mail(&self, subject: String, body: String) -> Result<()> { fn send_mail(&self, subject: String, body: String) -> Result<()> {
info!("Send mail {}", subject); info!("Send mail {}", subject);
if let Some(false) = self.config.test { let email = Message::builder()
let email = Message::builder() .from(Mailbox::new(
.to(Mailbox::new( Some(self.config.mail.from.1.clone()),
Some(self.config.mail.from.1.clone()), self.config.mail.from.0.parse::<Address>()?,
self.config.mail.from.0.parse::<Address>()?, ))
)) .to(self.config.mail.to.parse()?)
.from(self.config.mail.to.parse()?) .subject(subject)
.subject(subject) .body(body)?;
.body(body)?;
// Create transport // Create transport
let creds = Credentials::new( let creds = Credentials::new(
self.config.mail.username.clone(), self.config.mail.username.clone(),
self.config.mail.password.clone(), self.config.mail.password.clone(),
); );
// Open a remote connection to gmail // Open a remote connection
let mailer = SmtpTransport::relay(&self.config.mail.server) let mailer = if let Some(true) = self.config.test {
SmtpTransport::builder_dangerous(&self.config.mail.server)
.port(self.config.mail.port)
.build()
} else {
SmtpTransport::relay(&self.config.mail.server)
.unwrap() .unwrap()
.credentials(creds) .credentials(creds)
.port(self.config.mail.port) .port(self.config.mail.port)
.build(); .build()
mailer.send(&email)?;
} else {
println!("subject: {} - body: {}", subject, body);
}; };
mailer.send(&email)?;
Ok(()) Ok(())
} }
} }