notifications.js : add template to email notification (prettify)

merge-requests/256/head
Moe 2020-07-12 15:37:14 -07:00
parent 4aa25f995a
commit 0bc88bab74
2 changed files with 273 additions and 10 deletions

View File

@ -1,5 +1,6 @@
var fs = require("fs")
var Discord = require("discord.js")
var template = require("./notifications/emailTemplate.js")
module.exports = function(s,config,lang){
//discord bot
if(config.discordBot === true){
@ -298,18 +299,30 @@ module.exports = function(s,config,lang){
delete(s.group[d.ke].activeMonitors[d.id].detector_mail);
},detector_mail_timeout);
var files = []
var mailOptions = {
from: config.mail.from, // sender address
to: r.mail, // list of receivers
subject: lang.Event+' - '+d.screenshotName, // Subject line
html: '<i>'+lang.EventText1+' '+d.currentTimestamp+'.</i>',
attachments: files
}
var sendMail = function(){
Object.keys(d.details).forEach(function(v,n){
mailOptions.html+='<div><b>'+v+'</b> : '+d.details[v]+'</div>'
const infoRows = []
Object.keys(d.details).forEach(function(key){
var value = d.details[key]
var text = value
if(value instanceof Object){
text = JSON.stringify(value,null,3)
}
infoRows.push(template.createRow({
title: key,
text: text
}))
})
s.nodemailer.sendMail(mailOptions, (error, info) => {
s.nodemailer.sendMail({
from: config.mail.from,
to: r.mail,
subject: lang.Event+' - '+d.screenshotName,
html: template.createFramework({
title: lang.EventText1 + ' ' + d.currentTimestamp,
subtitle: 'Shinobi Event',
body: infoRows.join(''),
}),
attachments: files
}, (error, info) => {
if (error) {
s.systemLog(lang.MailError,error)
return false;

View File

@ -0,0 +1,250 @@
// Example of how to generate HTML for an email.
// createFramework({
// title: 'Password Reset',
// subtitle: 'If you did not make this request please change your password.',
// body: [
// createRow({
// title: 'Customer',
// text: `<span style="border:0;margin:0;padding:0;color:inherit;text-decoration:none">${customer.email}</span> — ${customer.id}`
// }),
// createRow({
// btn: {
// text: 'Confirm Password Reset',
// href: `https://licenses.shinobi.video/forgot/reset?code=${newCode}`
// }
// }),
// createRow({
// title: 'Reset Code',
// text: newCode
// }),
// ].join(''),
// })
module.exports = {
createRow : (options) => {
const trFillers = `<tr>
<td colspan="3" height="11" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="1" style="border:0;margin:0;padding:0;border:1px solid #ffffff;border-width:1px 0 0 0;font-size:1px;line-height:1px;max-height:1px">
<div>&nbsp;</div>
</td>
</tr>`
if(options.btn){
return `<tr>
<td style="border:0;margin:0;padding:0">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="3" height="12" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="16">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;color:#525f7f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;line-height:24px">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="center" height="38" valign="middle" style="border:0;margin:0;padding:0;background-color:#666ee8;border-radius:5px;text-align:center">
<a style="border:0;margin:0;padding:0;color:#ffffff;display:block;height:38px;text-align:center;text-decoration:none" href="${options.btn.href}" target="_blank">
<span style="border:0;margin:0;padding:0;color:#ffffff;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;font-weight:bold;height:38px;line-height:38px;text-decoration:none;vertical-align:middle;white-space:nowrap;width:100%">
${options.btn.text}
</span>
</a>
</td>
</tr>
</tbody>
</table>
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="16">
<div>&nbsp;</div>
</td>
</tr>
${trFillers}
</tbody>
</table>
</td>
</tr>`
}
return `<tr>
<td style="border:0;margin:0;padding:0">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="3" height="12" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="16">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;color:#525f7f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;line-height:24px">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="border:0;margin:0;padding:0;color:#8898aa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:12px;font-weight:bold;line-height:16px;text-transform:uppercase">
${options.title}
</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td height="4" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="border:0;margin:0;padding:0;color:#525f7f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;line-height:24px">
${options.text}
</td>
</tr>
</tbody>
</table>
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="16">
<div>&nbsp;</div>
</td>
</tr>
${trFillers}
</tbody>
</table>
</td>
</tr>`
},
createFramework : (options) => {
return `<div bgcolor="f6f9fc" style="border:0;margin:40px 0 40px 0;padding:0;min-width:100%;width:100%;/* text-align: center; */">
<table border="0" cellpadding="0" cellspacing="0" width="600" style="min-width:600px">
<tbody>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;color:#32325d;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:24px;line-height:32px">
<span class="m_4782828237464230064st-Delink m_4782828237464230064st-Delink--title" style="border:0;margin:0;padding:0;color:#32325d;text-decoration:none">${options.title}</span>
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="8" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="600" style="min-width:600px">
<tbody>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;color:#525f7f!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;line-height:24px">${options.subtitle}</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="12" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="600" style="min-width:600px">
<tbody>
<tr>
<td colspan="3" height="4" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0">
<table bgcolor="f6f9fc" border="0" cellpadding="0" cellspacing="0" style="border-radius:5px" width="100%">
<tbody>
${options.body}
<tr>
<td colspan="3" height="12" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="16" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="600" style="min-width:600px">
<tbody>
<tr>
<td colspan="3" height="20" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px" width="64">
<div>&nbsp;</div>
</td>
<td bgcolor="#e6ebf1" height="1" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px" width="64">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="31" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px;max-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
${options.footerText ? `<table border="0" cellpadding="0" cellspacing="0" width="600" style="min-width:600px">
<tbody>
<tr>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
<td style="border:0;margin:0;padding:0;color:#525f7f!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Ubuntu,sans-serif;font-size:16px;line-height:24px">
${options.footerText}
</td>
<td style="border:0;margin:0;padding:0;font-size:1px;line-height:1px" width="64">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" height="12" style="border:0;margin:0;padding:0;font-size:1px;line-height:1px">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>` : ''}
</div>`
}
}