From c20b8c665af8632ca232c1b40a9a0f2352e87b5f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 10 Jun 2025 13:20:44 +0800 Subject: [PATCH] add tests notification for email --- server/controllers/notificationController.js | 2 +- server/service/notificationService.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/controllers/notificationController.js b/server/controllers/notificationController.js index edb18adfb..df16f7a75 100755 --- a/server/controllers/notificationController.js +++ b/server/controllers/notificationController.js @@ -90,7 +90,7 @@ class NotificationController { const notification = req.body; if (notification?.type === "email") { - console.log("HANDLE EMAIL"); + const result = await this.notificationService.sendTestEmail(notification); return res.success({ msg: this.stringService.emailSendSuccess, }); diff --git a/server/service/notificationService.js b/server/service/notificationService.js index 56c6d2c1c..30c8474c1 100755 --- a/server/service/notificationService.js +++ b/server/service/notificationService.js @@ -196,6 +196,24 @@ class NotificationService { return true; } + sendTestEmail = async (notification) => { + const to = notification?.address; + if (!to || typeof to !== "string") { + throw new Error(this.stringService.errorForValidEmailAddress); + } + + const subject = this.stringService.testEmailSubject; + const context = { testName: "Monitoring System" }; + + const messageId = await this.emailService.buildAndSendEmail( + "testEmailTemplate", + context, + to, + subject + ); + console.log(messageId); + }; + /** * Sends an email notification about monitor status change *