[enh] add cc for mail in webDiffServers
This commit is contained in:
@@ -4,7 +4,7 @@ import {ConfMail} from './types/conf'
|
||||
import * as nodemailer from 'nodemailer'
|
||||
import * as os from 'os'
|
||||
|
||||
export async function sendMail(conf: ConfMail, subject: string, html: string) {
|
||||
export async function sendMail(conf: ConfMail, subject: string, html: string, cc?: string) {
|
||||
|
||||
if (conf.enabled) {
|
||||
let transporter = nodemailer.createTransport({
|
||||
@@ -23,7 +23,7 @@ export async function sendMail(conf: ConfMail, subject: string, html: string) {
|
||||
let info = await transporter.sendMail({
|
||||
from: conf.from,
|
||||
to: conf.to,
|
||||
cc: conf.cc,
|
||||
cc: (conf.cc ? [conf.cc] : []).concat(cc ? [cc] : []).join(','),
|
||||
subject,
|
||||
html
|
||||
})
|
||||
@@ -37,9 +37,9 @@ export const mail = {
|
||||
Connection from [${os.hostname}] to ${target} established on ${moment().format('DD-MM-YYYY HH:mm:ss')}.
|
||||
</p>
|
||||
`) => {
|
||||
return async () => {
|
||||
return async (cc?: string) => {
|
||||
console.log(`${message}`)
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml())
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,10 +51,10 @@ export const mail = {
|
||||
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
|
||||
</p>
|
||||
`) => {
|
||||
return async (waitingDelay: number) => {
|
||||
return async (waitingDelay: number, cc?: string) => {
|
||||
console.log(`${message}`)
|
||||
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(waitingDelay))
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(waitingDelay), cc)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -63,9 +63,9 @@ export const mail = {
|
||||
Connection from [${os.hostname}] to ${target} was recovered on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
||||
</p>
|
||||
`) => {
|
||||
return async () => {
|
||||
return async (cc?: string) => {
|
||||
console.log(`${message}`)
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml())
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface ConfWebDiff {
|
||||
file1: string
|
||||
file2: string
|
||||
frequency: number
|
||||
cc?: string
|
||||
}
|
||||
|
||||
export interface ConfBMA extends ConfURL {
|
||||
|
||||
@@ -62,21 +62,21 @@ export function webDiffWatcher(conf: Conf) {
|
||||
|
||||
conf.reconnectionDelays,
|
||||
|
||||
mail.onEstablished(conf, target, 'webdiff successfully started'),
|
||||
() => mail.onEstablished(conf, target, 'webdiff successfully started')(webDiffConf.cc),
|
||||
|
||||
// When a disconnection is detected
|
||||
mail.onDisconnect(conf, target, 'Diff detected', (waitingDelay: number) => `
|
||||
(waitingDelay: number) => mail.onDisconnect(conf, target, 'Diff detected', (waitingDelay: number) => `
|
||||
${htmlDiff}
|
||||
<p>
|
||||
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
|
||||
</p>
|
||||
`),
|
||||
`)(waitingDelay, webDiffConf.cc),
|
||||
|
||||
async () => {
|
||||
console.log('Trying to connect to %s', target)
|
||||
},
|
||||
|
||||
mail.onRestartSuccess(conf, target),
|
||||
() => mail.onRestartSuccess(conf, target)(webDiffConf.cc),
|
||||
|
||||
async (e) => {
|
||||
console.error(e.message)
|
||||
|
||||
Reference in New Issue
Block a user