From 6ae49f9a763cb8eb4e5ce45473a5f08f1ffdbbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Obernd=C3=B6rfer?= Date: Sat, 7 Dec 2024 15:16:47 +0100 Subject: [PATCH] Changed mailing logic to get receivers out of database not envs anymore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Florian Oberndörfer --- apps/backend/.env.example | 3 +-- apps/backend/src/app/utils/mail/mail.service.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/backend/.env.example b/apps/backend/.env.example index a9fe94a..e2a4a29 100644 --- a/apps/backend/.env.example +++ b/apps/backend/.env.example @@ -10,5 +10,4 @@ MAIL_HOST=smtp.example.com MAIL_PORT=465 MAIL_USER=user@example.com MAIL_PASSWORD=topsecret -MAIL_FROM=noreply@example.com -MAILING_LIST=example1@example.com,example2@example.com \ No newline at end of file +MAIL_FROM=noreply@example.com \ No newline at end of file diff --git a/apps/backend/src/app/utils/mail/mail.service.ts b/apps/backend/src/app/utils/mail/mail.service.ts index b96b3ae..ba1c641 100644 --- a/apps/backend/src/app/utils/mail/mail.service.ts +++ b/apps/backend/src/app/utils/mail/mail.service.ts @@ -28,8 +28,18 @@ export class MailService { } async sendAlertMail(alert: Alert) { - const receivers = - this.configService.getOrThrow('MAILING_LIST').split(',') || []; + const receiverEntities = await this.getAllMailReceiver(); + + if (receiverEntities.length === 0) { + this.logger.log('No mail receivers found. Skipping sending mail'); + return; + } + const receivers = receiverEntities + .map((receiver) => receiver.mail) + .join(',') + .split(','); + + console.log('receivers', receivers); let reason = ''; let description = '';