Quelques corrections
This commit is contained in:
parent
b912f9140e
commit
fc65a4069d
4 changed files with 472 additions and 391 deletions
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…
Add table
Add a link
Reference in a new issue