From f4cb051b842307fa74cfbf93c0ca69a158343212 Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 21 Jan 2024 16:00:41 +0100 Subject: [PATCH] fix mail error --- src/model/mail.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/model/mail.rs b/src/model/mail.rs index 4bdf8c1..dc5aff7 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -128,26 +128,37 @@ Der Vorstand .parse() .unwrap()); let splitted = send_to.split(','); + let send_mail = false; for single_rec in splitted { - email = email.bcc(single_rec.parse().unwrap()); + match single_rec.parse() { + Ok(val) => { + email = email.bcc(val); + send_mail = true; + } + Err(_) => { + println!("Error in mail: {single_rec}"); + } + } } - let email = email - .subject("ASKÖ Ruderverein Donau Linz | Vereinsgebühren") - .header(ContentType::TEXT_PLAIN) - .body(content) - .unwrap(); + if send_mail { + let email = email + .subject("ASKÖ Ruderverein Donau Linz | Vereinsgebühren") + .header(ContentType::TEXT_PLAIN) + .body(content) + .unwrap(); - let creds = - Credentials::new("no-reply@rudernlinz.at".to_owned(), smtp_pw.clone()); + let creds = + Credentials::new("no-reply@rudernlinz.at".to_owned(), smtp_pw.clone()); - let mailer = SmtpTransport::relay("mail.your-server.de") - .unwrap() - .credentials(creds) - .build(); + let mailer = SmtpTransport::relay("mail.your-server.de") + .unwrap() + .credentials(creds) + .build(); - // Send the email - mailer.send(&email).unwrap(); + // Send the email + mailer.send(&email).unwrap(); + } } } }