Allow HTML for custom email bodies (#5635)

This commit is contained in:
youpie 2025-05-01 19:36:34 +02:00 committed by GitHub
parent 8396330552
commit b22969a3e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View file

@ -42,6 +42,7 @@ class SMTP extends NotificationProvider {
// default values in case the user does not want to template // default values in case the user does not want to template
let subject = msg; let subject = msg;
let body = msg; let body = msg;
let useHTMLBody = false;
if (heartbeatJSON) { if (heartbeatJSON) {
body = `${msg}\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`; 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 // cannot end with whitespace as this often raises spam scores
const customSubject = notification.customSubject?.trim() || ""; const customSubject = notification.customSubject?.trim() || "";
const customBody = notification.customBody?.trim() || ""; const customBody = notification.customBody?.trim() || "";
if (customSubject !== "") { if (customSubject !== "") {
subject = await this.renderTemplate(customSubject, msg, monitorJSON, heartbeatJSON); subject = await this.renderTemplate(customSubject, msg, monitorJSON, heartbeatJSON);
} }
if (customBody !== "") { if (customBody !== "") {
useHTMLBody = notification.htmlBody || false;
body = await this.renderTemplate(customBody, msg, monitorJSON, heartbeatJSON); body = await this.renderTemplate(customBody, msg, monitorJSON, heartbeatJSON);
} }
} }
@ -67,7 +68,8 @@ class SMTP extends NotificationProvider {
bcc: notification.smtpBCC, bcc: notification.smtpBCC,
to: notification.smtpTo, to: notification.smtpTo,
subject: subject, 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; return okMsg;

View file

@ -79,6 +79,15 @@
<div class="form-text">{{ $t("leave blank for default body") }}</div> <div class="form-text">{{ $t("leave blank for default body") }}</div>
</div> </div>
<div class="mb-3">
<div class="form-check">
<input id="use-html-body" v-model="$parent.notification.htmlBody" class="form-check-input" type="checkbox" value="">
<label class="form-check-label" for="use-html-body">
{{ $t("Use HTML for custom E-mail body") }}
</label>
</div>
</div>
<ToggleSection :heading="$t('smtpDkimSettings')"> <ToggleSection :heading="$t('smtpDkimSettings')">
<i18n-t tag="div" keypath="smtpDkimDesc" class="form-text mb-3"> <i18n-t tag="div" keypath="smtpDkimDesc" class="form-text mb-3">
<a href="https://nodemailer.com/dkim/" target="_blank">{{ $t("documentation") }}</a> <a href="https://nodemailer.com/dkim/" target="_blank">{{ $t("documentation") }}</a>

View file

@ -517,6 +517,7 @@
"Clone": "Clone", "Clone": "Clone",
"cloneOf": "Clone of {0}", "cloneOf": "Clone of {0}",
"smtp": "Email (SMTP)", "smtp": "Email (SMTP)",
"Use HTML for custom E-mail body": "Use HTML for custom E-mail body",
"secureOptionNone": "None / STARTTLS (25, 587)", "secureOptionNone": "None / STARTTLS (25, 587)",
"secureOptionTLS": "TLS (465)", "secureOptionTLS": "TLS (465)",
"Ignore TLS Error": "Ignore TLS Error", "Ignore TLS Error": "Ignore TLS Error",