mirror of
https://github.com/louislam/uptime-kuma.git
synced 2026-06-19 07:36:11 +00:00
feat(notification): add additional headers option for SMTP (#7506)
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
@@ -15,6 +15,7 @@ class SMTP extends NotificationProvider {
|
||||
host: notification.smtpHost,
|
||||
port: notification.smtpPort,
|
||||
secure: notification.smtpSecure,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
// Handle TLS/STARTTLS options
|
||||
@@ -54,6 +55,18 @@ class SMTP extends NotificationProvider {
|
||||
};
|
||||
}
|
||||
|
||||
// Handle additional headers
|
||||
if (notification.smtpAdditionalHeaders) {
|
||||
try {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
...JSON.parse(notification.smtpAdditionalHeaders),
|
||||
};
|
||||
} catch (err) {
|
||||
throw new Error("Additional Headers is not a valid JSON");
|
||||
}
|
||||
}
|
||||
|
||||
// default values in case the user does not want to template
|
||||
let subject = msg;
|
||||
let body = msg;
|
||||
@@ -83,6 +96,7 @@ class SMTP extends NotificationProvider {
|
||||
bcc: notification.smtpBCC,
|
||||
to: notification.smtpTo,
|
||||
subject: subject,
|
||||
headers: config.headers,
|
||||
// If the email body is custom, and the user wants it, set the email body as HTML
|
||||
[useHTMLBody ? "html" : "text"]: body,
|
||||
});
|
||||
|
||||
@@ -183,6 +183,31 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input v-model="showAdditionalHeadersField" class="form-check-input" type="checkbox" />
|
||||
<label class="form-check-label">{{ $t("smtpAdditionalHeadersTitle") }}</label>
|
||||
</div>
|
||||
<i18n-t
|
||||
v-if="showAdditionalHeadersField"
|
||||
tag="div"
|
||||
keypath="smtpAdditionalHeadersDesc"
|
||||
class="form-text mb-3"
|
||||
>
|
||||
<a href="https://nodemailer.com/message/custom-headers" target="_blank">{{ $t("documentation") }}</a>
|
||||
</i18n-t>
|
||||
|
||||
<textarea
|
||||
v-if="showAdditionalHeadersField"
|
||||
id="additional-headers"
|
||||
v-model="$parent.notification.smtpAdditionalHeaders"
|
||||
class="form-control"
|
||||
rows="5"
|
||||
:placeholder="headersPlaceholder"
|
||||
:required="showAdditionalHeadersField"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<ToggleSection :heading="$t('smtpDkimSettings')">
|
||||
<i18n-t tag="div" keypath="smtpDkimDesc" class="form-text mb-3">
|
||||
<a href="https://nodemailer.com/dkim/" target="_blank">{{ $t("documentation") }}</a>
|
||||
@@ -272,6 +297,11 @@ export default {
|
||||
TemplatedTextarea,
|
||||
ToggleSection,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showAdditionalHeadersField: this.$parent.notification.smtpAdditionalHeaders != null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
hasRecipient() {
|
||||
if (
|
||||
@@ -284,6 +314,13 @@ export default {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
headersPlaceholder() {
|
||||
return this.$t("Example:", [
|
||||
`{
|
||||
"X-Custom-Header": "Additional Header"
|
||||
}`,
|
||||
]);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (typeof this.$parent.notification.smtpSecure === "undefined") {
|
||||
|
||||
@@ -896,6 +896,8 @@
|
||||
"slackUseTemplateDescription": "If enabled, the message will be sent using a custom template. You can use Liquid templating to include monitor group information via monitorJSON.path or monitorJSON.pathName.",
|
||||
"aboutChannelName": "Enter the channel name on {0} Channel Name field if you want to bypass the Webhook channel. Ex: #other-channel",
|
||||
"aboutKumaURL": "If you leave the Uptime Kuma URL field blank, it will default to the Project GitHub page.",
|
||||
"smtpAdditionalHeadersTitle": "Additional Headers",
|
||||
"smtpAdditionalHeadersDesc": "Please refer to the Nodemailer Custom Headers {0} for usage.",
|
||||
"smtpDkimSettings": "DKIM Settings",
|
||||
"smtpDkimDesc": "Please refer to the Nodemailer DKIM {0} for usage.",
|
||||
"documentation": "documentation",
|
||||
|
||||
Reference in New Issue
Block a user