From b22969a3e6c6fdf226325eca08347f369c0c4512 Mon Sep 17 00:00:00 2001 From: youpie <37704067+youpie@users.noreply.github.com> Date: Thu, 1 May 2025 19:36:34 +0200 Subject: [PATCH] Allow HTML for custom email bodies (#5635) --- server/notification-providers/smtp.js | 6 ++++-- src/components/notifications/SMTP.vue | 9 +++++++++ src/lang/en.json | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/notification-providers/smtp.js b/server/notification-providers/smtp.js index 980c7dfd3..d0ad5b728 100644 --- a/server/notification-providers/smtp.js +++ b/server/notification-providers/smtp.js @@ -42,6 +42,7 @@ class SMTP extends NotificationProvider { // default values in case the user does not want to template let subject = msg; let body = msg; + let useHTMLBody = false; if (heartbeatJSON) { body = `${msg}\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`; } @@ -50,11 +51,11 @@ class SMTP extends NotificationProvider { // cannot end with whitespace as this often raises spam scores const customSubject = notification.customSubject?.trim() || ""; const customBody = notification.customBody?.trim() || ""; - if (customSubject !== "") { subject = await this.renderTemplate(customSubject, msg, monitorJSON, heartbeatJSON); } if (customBody !== "") { + useHTMLBody = notification.htmlBody || false; body = await this.renderTemplate(customBody, msg, monitorJSON, heartbeatJSON); } } @@ -67,7 +68,8 @@ class SMTP extends NotificationProvider { bcc: notification.smtpBCC, to: notification.smtpTo, subject: subject, - text: body, + // If the email body is custom, and the user wants it, set the email body as HTML + [useHTMLBody ? "html" : "text"]: body }); return okMsg; diff --git a/src/components/notifications/SMTP.vue b/src/components/notifications/SMTP.vue index 4e0fb4b57..8f0e1501d 100644 --- a/src/components/notifications/SMTP.vue +++ b/src/components/notifications/SMTP.vue @@ -79,6 +79,15 @@
{{ $t("leave blank for default body") }}
+
+
+ + +
+
+ {{ $t("documentation") }} diff --git a/src/lang/en.json b/src/lang/en.json index b089478f8..63c28b56c 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -517,6 +517,7 @@ "Clone": "Clone", "cloneOf": "Clone of {0}", "smtp": "Email (SMTP)", + "Use HTML for custom E-mail body": "Use HTML for custom E-mail body", "secureOptionNone": "None / STARTTLS (25, 587)", "secureOptionTLS": "TLS (465)", "Ignore TLS Error": "Ignore TLS Error",