[enh] add cc for mail in webDiffServers

This commit is contained in:
2019-08-31 18:19:09 +02:00
parent 8b60767622
commit 9966caa22a
3 changed files with 13 additions and 12 deletions

View File

@@ -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)
}
},