From 4ca48338b6ee3f6f09640e4cd9b6a8b0eb3dd47e Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:12:16 +0700 Subject: [PATCH 01/16] Add SendGrid Email --- server/notification-providers/send-grid.js | 65 ++++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/SendGrid.vue | 35 ++++++++++++ src/components/notifications/index.js | 4 +- 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/send-grid.js create mode 100644 src/components/notifications/SendGrid.vue diff --git a/server/notification-providers/send-grid.js b/server/notification-providers/send-grid.js new file mode 100644 index 0000000000..0fc7668bb1 --- /dev/null +++ b/server/notification-providers/send-grid.js @@ -0,0 +1,65 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SendGrid extends NotificationProvider { + name = "sendgrid"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${notification.sendgridApiKey}`, + }, + }; + + let personalizations = { + to: [{ email: notification.sendgridToEmail }], + }; + + // Add CC recipients if provided + if (notification.sendgridCcEmail) { + personalizations.cc = notification.sendgridCcEmail + .split(",") + .map((email) => ({ email: email.trim() })); + } + + // Add BCC recipients if provided + if (notification.sendgridBccEmail) { + personalizations.bcc = notification.sendgridBccEmail + .split(",") + .map((email) => ({ email: email.trim() })); + } + + let data = { + personalizations: [personalizations], + from: { email: notification.sendgridFromEmail }, + subject: + notification.sendgridSubject || + "Notification from Your Uptime Kuma", + content: [ + { + type: "text/plain", + value: msg, + }, + ], + }; + + await axios.post( + "https://api.sendgrid.com/v3/mail/send", + data, + config + ); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SendGrid; diff --git a/server/notification.js b/server/notification.js index 26daeb0428..e7977eb4af 100644 --- a/server/notification.js +++ b/server/notification.js @@ -68,6 +68,7 @@ const GtxMessaging = require("./notification-providers/gtx-messaging"); const Cellsynt = require("./notification-providers/cellsynt"); const Onesender = require("./notification-providers/onesender"); const Wpush = require("./notification-providers/wpush"); +const SendGrid = require("./notification-providers/send-grid"); class Notification { @@ -153,6 +154,7 @@ class Notification { new GtxMessaging(), new Cellsynt(), new Wpush(), + new SendGrid() ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index ec86d15f8a..88343885d1 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -165,6 +165,7 @@ export default { "whapi": "WhatsApp (Whapi)", "gtxmessaging": "GtxMessaging", "Cellsynt": "Cellsynt", + "SendGrid": "SendGrid (Email)" }; // Put notifications here if it's not supported in most regions or its documentation is not in English diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue new file mode 100644 index 0000000000..6d7a35fdce --- /dev/null +++ b/src/components/notifications/SendGrid.vue @@ -0,0 +1,35 @@ + \ No newline at end of file diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 35a3a920ad..9197b03559 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -66,6 +66,7 @@ import Whapi from "./Whapi.vue"; import Cellsynt from "./Cellsynt.vue"; import WPush from "./WPush.vue"; import SIGNL4 from "./SIGNL4.vue"; +import SendGrid from "./SendGrid.vue"; /** * Manage all notification form. @@ -139,7 +140,8 @@ const NotificationFormList = { "whapi": Whapi, "gtxmessaging": GtxMessaging, "Cellsynt": Cellsynt, - "WPush": WPush + "WPush": WPush, + "SendGrid": SendGrid }; export default NotificationFormList; From 6e19fbf3c9e69d452d990aed7d43db58e5e57ab3 Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:25:42 +0700 Subject: [PATCH 02/16] fix type name not same --- server/notification-providers/send-grid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/notification-providers/send-grid.js b/server/notification-providers/send-grid.js index 0fc7668bb1..b93840b973 100644 --- a/server/notification-providers/send-grid.js +++ b/server/notification-providers/send-grid.js @@ -2,7 +2,7 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); class SendGrid extends NotificationProvider { - name = "sendgrid"; + name = "SendGrid"; /** * @inheritdoc From 6e2acd0dcfde0d6ace0059cfa2f90b81ba5976bf Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:05:36 +0700 Subject: [PATCH 03/16] Update src/components/notifications/SendGrid.vue Co-authored-by: Frank Elsinga --- src/components/notifications/SendGrid.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue index 6d7a35fdce..eba0fa35f6 100644 --- a/src/components/notifications/SendGrid.vue +++ b/src/components/notifications/SendGrid.vue @@ -32,4 +32,4 @@ https://docs.sendgrid.com/api-reference/mail-send/mail-send - \ No newline at end of file + From 598f8e24720d9ad260cff2fe061a6dc2a60a51ca Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:05:43 +0700 Subject: [PATCH 04/16] Update src/components/notifications/SendGrid.vue Co-authored-by: Frank Elsinga --- src/components/notifications/SendGrid.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue index eba0fa35f6..6977aa1999 100644 --- a/src/components/notifications/SendGrid.vue +++ b/src/components/notifications/SendGrid.vue @@ -15,7 +15,7 @@
- {{ $t("Separate multiple email addresses with commas") }} +
{{ $t("Separate multiple email addresses with commas") }}
From 20fa15a54958223c59fed21287b57f4828144973 Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:05:53 +0700 Subject: [PATCH 05/16] Update src/components/notifications/SendGrid.vue Co-authored-by: Frank Elsinga --- src/components/notifications/SendGrid.vue | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue index 6977aa1999..e5cfe964b0 100644 --- a/src/components/notifications/SendGrid.vue +++ b/src/components/notifications/SendGrid.vue @@ -27,9 +27,7 @@ {{ $t("Default subject will be used if left empty") }}
- + + https://docs.sendgrid.com/api-reference/mail-send/mail-send + From 0c7fc36e43bf96db80e5fd923c6e5f219f0bf71e Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:06:04 +0700 Subject: [PATCH 06/16] Update src/components/notifications/index.js Co-authored-by: Frank Elsinga --- src/components/notifications/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 9197b03559..efa2af5c49 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -141,7 +141,7 @@ const NotificationFormList = { "gtxmessaging": GtxMessaging, "Cellsynt": Cellsynt, "WPush": WPush, - "SendGrid": SendGrid + "SendGrid": SendGrid, }; export default NotificationFormList; From eeafb95d55e2a6e5863b9d055cf1f36bf46e009b Mon Sep 17 00:00:00 2001 From: sctnightcore <23263315+sctnightcore@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:06:20 +0700 Subject: [PATCH 07/16] Update src/components/notifications/SendGrid.vue Co-authored-by: Frank Elsinga --- src/components/notifications/SendGrid.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue index e5cfe964b0..b78a9975cd 100644 --- a/src/components/notifications/SendGrid.vue +++ b/src/components/notifications/SendGrid.vue @@ -1,5 +1,4 @@