2023-09-27 17:04:17 +00:00
|
|
|
import { NotificationProvider } from './type';
|
|
|
|
import nodemailer from 'nodemailer';
|
|
|
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
|
|
|
|
|
|
interface SMTPPayload {
|
|
|
|
hostname: string;
|
|
|
|
port: number;
|
|
|
|
security: boolean;
|
|
|
|
ignoreTLS: boolean;
|
|
|
|
username: string;
|
|
|
|
password: string;
|
|
|
|
from: string;
|
|
|
|
to: string;
|
|
|
|
cc?: string;
|
|
|
|
bcc?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fork from https://github.com/louislam/uptime-kuma/blob/HEAD/server/notification-providers/smtp.js
|
|
|
|
export const smtp: NotificationProvider = {
|
2023-10-19 16:28:46 +00:00
|
|
|
send: async (notification, title, message) => {
|
2023-09-27 17:04:17 +00:00
|
|
|
const payload = notification.payload as unknown as SMTPPayload;
|
|
|
|
|
|
|
|
const config: SMTPTransport.Options = {
|
|
|
|
host: payload.hostname,
|
|
|
|
port: payload.port,
|
|
|
|
secure: payload.security,
|
|
|
|
ignoreTLS: payload.ignoreTLS,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (payload.username || payload.password) {
|
|
|
|
config.auth = {
|
|
|
|
user: payload.username,
|
|
|
|
pass: payload.password,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-19 16:28:46 +00:00
|
|
|
const subject = title;
|
2023-09-27 17:04:17 +00:00
|
|
|
const bodyTextContent = message;
|
|
|
|
|
|
|
|
const transporter = nodemailer.createTransport(config);
|
|
|
|
await transporter.sendMail({
|
|
|
|
from: payload.from,
|
|
|
|
to: payload.to,
|
|
|
|
cc: payload.cc,
|
|
|
|
bcc: payload.bcc,
|
|
|
|
subject: subject,
|
|
|
|
text: bodyTextContent,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|