[mod] e-mails plus explicites (titre + motif erreur)
This commit is contained in:
@@ -6,6 +6,8 @@ import * as os from 'os'
|
||||
|
||||
export async function sendMail(conf: ConfMail, subject: string, html: string, cc?: string) {
|
||||
|
||||
console.log(`[mail] Subject: ${subject}`)
|
||||
console.log(`[mail] Body: ${html}`)
|
||||
if (conf.enabled) {
|
||||
let transporter = nodemailer.createTransport({
|
||||
host: conf.host,
|
||||
@@ -38,23 +40,22 @@ export const mail = {
|
||||
</p>
|
||||
`) => {
|
||||
return async (cc?: string) => {
|
||||
console.log(`${message}`)
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
await sendMail(conf.mail, `[dw] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
}
|
||||
},
|
||||
|
||||
onDisconnect: (conf: Conf, target: string, message = `Connection closed for ${target}`, getHtml: (waitingDelay: number) => string = (waitingDelay: number) => `
|
||||
onDisconnect: (conf: Conf, target: string, message = `Connection closed for ${target}`, getErrorMessage: () => string = () => '', getHtml: (waitingDelay: number) => string = (waitingDelay: number) => `
|
||||
<p>
|
||||
Connection from [${os.hostname}] to ${target} was lost on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
||||
</p>
|
||||
<p>
|
||||
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
|
||||
</p>
|
||||
${getErrorMessage()}
|
||||
`) => {
|
||||
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), cc)
|
||||
await sendMail(conf.mail, `[dw] [${os.hostname}] ${message}`, getHtml(waitingDelay), cc)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -65,21 +66,7 @@ export const mail = {
|
||||
`) => {
|
||||
return async (cc?: string) => {
|
||||
console.log(`${message}`)
|
||||
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
await sendMail(conf.mail, `[dw] [${os.hostname}] ${message}`, getHtml(), cc)
|
||||
}
|
||||
},
|
||||
|
||||
onError: (conf: Conf, target: string) => {
|
||||
return async (e: Error) => {
|
||||
console.error(e.message || e)
|
||||
// await sendMail(conf.mail, `[dwatcher] Connection error`, `
|
||||
// <p>
|
||||
// Connection from [${os.hostname}] error with ${target} on ${moment().format('dd-MM-YYYY HH:mm:ss')}:
|
||||
// </p>
|
||||
// <p>
|
||||
// ${e.message}
|
||||
// </p>
|
||||
// `)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user