implement smtp

pull/6/head
LouisLam 4 years ago
parent 0ad04d1468
commit 072e86542a

5
package-lock.json generated

@ -2261,6 +2261,11 @@
}
}
},
"nodemailer": {
"version": "6.6.2",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.2.tgz",
"integrity": "sha512-YSzu7TLbI+bsjCis/TZlAXBoM4y93HhlIgo0P5oiA2ua9Z4k+E2Fod//ybIzdJxOlXGRcHIh/WaeCBehvxZb/Q=="
},
"nopt": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",

@ -16,6 +16,7 @@
"express": "^4.17.1",
"form-data": "^4.0.0",
"jsonwebtoken": "^8.5.1",
"nodemailer": "^6.6.2",
"password-hash": "^1.2.2",
"redbean-node": "0.0.20",
"socket.io": "^4.0.2",

@ -1,6 +1,7 @@
const axios = require("axios");
const {R} = require("redbean-node");
const FormData = require('form-data');
const nodemailer = require("nodemailer");
class Notification {
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
@ -42,15 +43,14 @@ class Notification {
}
let res = await axios.post(notification.webhookURL, finalData, config)
console.log(res.data)
return true;
} catch (error) {
console.log(error)
return false;
}
} else if (notification.type === "smtp") {
return await Notification.smtp(notification, msg)
} else {
throw new Error("Notification type is not supported")
}
@ -91,6 +91,29 @@ class Notification {
await R.trash(bean)
}
static async smtp(notification, msg) {
let transporter = nodemailer.createTransport({
host: notification.smtpHost,
port: notification.smtpPort,
secure: notification.smtpSecure,
auth: {
user: notification.smtpUsername,
pass: notification.smtpPassword,
},
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: `"Uptime Kuma" <${notification.smtpFrom}>`,
to: notification.smtpTo,
subject: msg,
text: msg,
});
return true;
}
}
module.exports = {

@ -15,7 +15,7 @@
<select class="form-select" id="type" v-model="notification.type">
<option value="telegram">Telegram</option>
<option value="webhook">Webhook</option>
<option value="email">Email</option>
<option value="smtp">Email (SMTP)</option>
<option value="discord">Discord</option>
</select>
</div>
@ -82,6 +82,46 @@
</div>
</template>
<template v-if="notification.type === 'smtp'">
<div class="mb-3">
<label for="hostname" class="form-label">Hostname</label>
<input type="text" class="form-control" id="hostname" required v-model="notification.smtpHost">
</div>
<div class="mb-3">
<label for="port" class="form-label">Port</label>
<input type="number" class="form-control" id="port" v-model="notification.smtpPort" required min="0" max="65535" step="1">
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" value="" id="secure" v-model="notification.smtpSecure">
<label class="form-check-label" for="secure">
Secure
</label>
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" required v-model="notification.smtpUsername" autocomplete="false">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" required v-model="notification.smtpPassword" autocomplete="false">
</div>
<div class="mb-3">
<label for="from-email" class="form-label">From Email</label>
<input type="email" class="form-control" id="from-email" required v-model="notification.smtpFrom" autocomplete="false">
</div>
<div class="mb-3">
<label for="to-email" class="form-label">To Email</label>
<input type="email" class="form-control" id="to-email" required v-model="notification.smtpTo" autocomplete="false">
</div>
</template>
</div>
<div class="modal-footer">

Loading…
Cancel
Save