Quelques corrections
This commit is contained in:
parent
b912f9140e
commit
fc65a4069d
4 changed files with 472 additions and 391 deletions
814
Cargo.lock
generated
814
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
lettre = "0.10"
|
||||
toml = "0.5"
|
||||
toml = "0.7"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
log = "0.4"
|
||||
simplelog = "0.12"
|
||||
|
|
3
TODO.md
3
TODO.md
|
@ -4,4 +4,5 @@
|
|||
* [ ] Rustfmt
|
||||
* [ ] Logs tournant
|
||||
* [ ] 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
|
44
src/main.rs
44
src/main.rs
|
@ -199,34 +199,36 @@ impl Tester {
|
|||
fn send_mail(&self, subject: String, body: String) -> Result<()> {
|
||||
info!("Send mail {}", subject);
|
||||
|
||||
if let Some(false) = self.config.test {
|
||||
let email = Message::builder()
|
||||
.to(Mailbox::new(
|
||||
Some(self.config.mail.from.1.clone()),
|
||||
self.config.mail.from.0.parse::<Address>()?,
|
||||
))
|
||||
.from(self.config.mail.to.parse()?)
|
||||
.subject(subject)
|
||||
.body(body)?;
|
||||
let email = Message::builder()
|
||||
.from(Mailbox::new(
|
||||
Some(self.config.mail.from.1.clone()),
|
||||
self.config.mail.from.0.parse::<Address>()?,
|
||||
))
|
||||
.to(self.config.mail.to.parse()?)
|
||||
.subject(subject)
|
||||
.body(body)?;
|
||||
|
||||
// Create transport
|
||||
let creds = Credentials::new(
|
||||
self.config.mail.username.clone(),
|
||||
self.config.mail.password.clone(),
|
||||
);
|
||||
// Create transport
|
||||
let creds = Credentials::new(
|
||||
self.config.mail.username.clone(),
|
||||
self.config.mail.password.clone(),
|
||||
);
|
||||
|
||||
// Open a remote connection to gmail
|
||||
let mailer = SmtpTransport::relay(&self.config.mail.server)
|
||||
// Open a remote connection
|
||||
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()
|
||||
.credentials(creds)
|
||||
.port(self.config.mail.port)
|
||||
.build();
|
||||
|
||||
mailer.send(&email)?;
|
||||
} else {
|
||||
println!("subject: {} - body: {}", subject, body);
|
||||
.build()
|
||||
};
|
||||
|
||||
mailer.send(&email)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue