diff --git a/server/notification-providers/resend.js b/server/notification-providers/resend.js new file mode 100644 index 000000000..08c417547 --- /dev/null +++ b/server/notification-providers/resend.js @@ -0,0 +1,49 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Resend extends NotificationProvider { + name = "Resend"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + Authorization: `Bearer ${notification.longLivedAccessToken}`, + "Content-Type": "application/json", + }, + }; + config = this.getAxiosConfigWithProxy(config); + const email = notification.resendFromEmail.trim(); + + const fromName = notification.resendFromName?.trim() + ? notification.resendFromName.trim() + : "Uptime Kuma"; + let data = { + from: `${fromName} <${email}>`, + to: notification.resendToEmail, + subject: notification.resendSubject || "Notification from Your Uptime Kuma", + html: `

${msg.replace(/\n/g, "
")}

` + }; + + let result = await axios.post( + "https://api.resend.com/emails", + data, + config + ); + if (result.status === 200) { + return okMsg; + } else { + throw new Error(`Unexpected status code: ${result.status}`); + } + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Resend; diff --git a/server/notification.js b/server/notification.js index e25bca08b..36c4cc617 100644 --- a/server/notification.js +++ b/server/notification.js @@ -78,6 +78,7 @@ const Onesender = require("./notification-providers/onesender"); const Wpush = require("./notification-providers/wpush"); const SendGrid = require("./notification-providers/send-grid"); const Brevo = require("./notification-providers/brevo"); +const Resend = require("./notification-providers/resend"); const YZJ = require("./notification-providers/yzj"); const SMSPlanet = require("./notification-providers/sms-planet"); const SpugPush = require("./notification-providers/spugpush"); @@ -176,6 +177,7 @@ class Notification { new Cellsynt(), new Wpush(), new Brevo(), + new Resend(), new YZJ(), new SMSPlanet(), new SpugPush(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 98df20abb..40b367a0b 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -173,6 +173,7 @@ export default { "Cellsynt": "Cellsynt", "SendGrid": "SendGrid", "Brevo": "Brevo", + "Resend": "Resend", "notifery": "Notifery", "Webpush": "Webpush", }; diff --git a/src/components/notifications/Resend.vue b/src/components/notifications/Resend.vue new file mode 100644 index 000000000..ea9e6a6ae --- /dev/null +++ b/src/components/notifications/Resend.vue @@ -0,0 +1,48 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 9bc4f050d..ee7511286 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -81,6 +81,7 @@ import YZJ from "./YZJ.vue"; import SMSPlanet from "./SMSPlanet.vue"; import SMSIR from "./SMSIR.vue"; import Webpush from "./Webpush.vue"; +import Resend from "./Resend.vue"; /** * Manage all notification form. @@ -167,6 +168,7 @@ const NotificationFormList = { "WPush": WPush, "SendGrid": SendGrid, "Brevo": Brevo, + "Resend":Resend, "YZJ": YZJ, "SMSPlanet": SMSPlanet, "Webpush": Webpush,