przygotowanie masowej wysyłki
parent
5e32104549
commit
564ee01f7f
|
@ -454,6 +454,38 @@ CREATE OR REPLACE VIEW \`sumy\` AS SELECT \`rozliczenie\`.\`wolontariuszID\` AS
|
|||
return toSend;
|
||||
}
|
||||
|
||||
function massEmail($emaile = [], $tytul = "Powiadomienie od sztabu", $tresc = "Brak treści wiadomości")
|
||||
{
|
||||
const nodemailer = require('nodemailer');
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTPHOST,
|
||||
port: process.env.SMTPPORT,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: process.env.SMTPLOGIN,
|
||||
pass: process.env.SMTPPASS
|
||||
}
|
||||
});
|
||||
$emaile.forEach(element => {
|
||||
const mailOptions = {
|
||||
from: process.env.SMTPLOGIN,
|
||||
bcc: element,
|
||||
subject: $tytul,
|
||||
html: '<img src="' + process.env.LOGO + '" height="150px" style="display: block; margin-left: auto; margin-right: auto;"><h1 style="text-align: center;">' + $tytul + '</h1><br><div id="main">' + $tresc + '</div><p style="text-align: center;">Pozdrawiamy,<br>' + process.env.SZTAB + '</p>' + footerHtml(0,1)
|
||||
};
|
||||
transporter.sendMail(mailOptions, function(error, info){
|
||||
if (error) {
|
||||
console.log(error);
|
||||
loger(fs, 'Błąd wysyłania maila do ' + element, 'error');
|
||||
} else {
|
||||
console.log('Email został wysłany: ' + info.response);
|
||||
loger(fs, 'Email został wysłany do ' + element + ' ' + info.response, 'info');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
exports.headerHtml = headerHtml;
|
||||
exports.menuHtml = menuHtml;
|
||||
exports.footerHtml = footerHtml;
|
||||
|
@ -466,3 +498,4 @@ exports.sendToDiscord = sendToDiscord;
|
|||
exports.sendEmail = sendEmail;
|
||||
exports.checkSendEmail = checkSendEmail;
|
||||
exports.baza = baza;
|
||||
exports.massEmail = massEmail;
|
|
@ -32,7 +32,7 @@ app.use(fileUpload({
|
|||
}));
|
||||
|
||||
//import functions from func.js
|
||||
const {headerHtml, menuHtml, footerHtml, checkPesel, loger, telefon, sendToDiscord, sendEmail, makeid, checkSendEmail, baza} = require('./func.js');
|
||||
const {headerHtml, menuHtml, footerHtml, checkPesel, loger, telefon, sendToDiscord, sendEmail, makeid, checkSendEmail, baza, massEmail} = require('./func.js');
|
||||
//function loger(fs, text, type = 'info')
|
||||
panelRouter.use(function(req, res, next) {
|
||||
var cookies = cookie.parse(req.headers.cookie || '');
|
||||
|
@ -1723,4 +1723,37 @@ panelRouter.all('/usunWolontariuszy', function(req, res) {
|
|||
});
|
||||
})
|
||||
|
||||
panelRouter.get('/wyslijEmaile', function(req, res) {
|
||||
//pobierz tytul i treść emaila, a potem bobierz wszystkie emaile (unikalne) i wyslij
|
||||
//treść uzupełnij za pomocą quill
|
||||
var toReturn = headerHtml("Wysyłanie emaili");
|
||||
toReturn += menuHtml(1);
|
||||
toReturn += '<div class="content">';
|
||||
toReturn += '<h1>Wysyłanie emaili</h1>';
|
||||
toReturn += '<form action="/panel/wyslijEmaile" method="POST">';
|
||||
toReturn += '<table class="dane">';
|
||||
toReturn += '<tr><td>Temat</td><td><input type="text" name="temat"></td></tr>';
|
||||
toReturn += '<tr><td>Treść</td><td><div id="editor"></div><textarea name="tresc" style="display:none;"></textarea></td></tr>';
|
||||
toReturn += '</table>';
|
||||
toReturn += '<input type="submit" value="Wyślij">';
|
||||
toReturn += '</form>';
|
||||
toReturn += '<link href="https://cdn.jsdelivr.net/npm/quill@2.0.3/dist/quill.snow.css" rel="stylesheet" />';
|
||||
toReturn += '<script src="https://cdn.jsdelivr.net/npm/quill@2.0.3/dist/quill.js"></script>';
|
||||
toReturn += '<script>';
|
||||
toReturn += 'var quill = new Quill("#editor", {';
|
||||
toReturn += 'theme: "snow",';
|
||||
toReturn += 'modules: {';
|
||||
toReturn += 'toolbar: [';
|
||||
toReturn += '[{ header: [1, 2, 3, false] }],';
|
||||
toReturn += `['bold', 'italic', 'underline', 'strike', 'blockquote', 'code-block'],`;
|
||||
toReturn += `[{ list: 'ordered'}`;
|
||||
toReturn += `, { list: 'bullet' }]`;
|
||||
toReturn += `['link', 'image', 'video']`;
|
||||
toReturn += ']';
|
||||
toReturn += '}';
|
||||
toReturn += '});';
|
||||
toReturn += '</div>';
|
||||
toReturn += footerHtml(1);
|
||||
});
|
||||
|
||||
module.exports = panelRouter;
|
Loading…
Reference in New Issue