send scheckbuch people mail after using all trips
All checks were successful
CI/CD Pipeline / test (push) Successful in 12m7s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2024-09-11 23:52:16 +02:00
parent 8408148ead
commit 1225aeac94
5 changed files with 165 additions and 29 deletions

View File

@ -5,7 +5,7 @@ use lettre::{
transport::smtp::authentication::Credentials,
Message, SmtpTransport, Transport,
};
use sqlx::SqlitePool;
use sqlx::{Sqlite, SqlitePool, Transaction};
use crate::tera::admin::mail::MailToSend;
@ -20,6 +20,19 @@ impl Mail {
subject: &str,
body: String,
smtp_pw: &str,
) -> Result<(), String> {
let mut tx = db.begin().await.unwrap();
let ret = Self::send_single_tx(&mut tx, to, subject, body, smtp_pw).await;
tx.commit().await.unwrap();
ret
}
pub async fn send_single_tx(
db: &mut Transaction<'_, Sqlite>,
to: &str,
subject: &str,
body: String,
smtp_pw: &str,
) -> Result<(), String> {
let mut email = Message::builder()
.from(
@ -40,7 +53,7 @@ impl Mail {
match single_rec.parse() {
Ok(new_bcc_mail) => email = email.bcc(new_bcc_mail),
Err(_) => {
Log::create(
Log::create_with_tx(
db,
format!("Mail not sent to {single_rec}, because it could not be parsed"),
)