Masowa wysyłka dokończenie

main
kry008 2025-01-03 09:40:01 +01:00
parent 2bcbb755dd
commit cd2ae830a2
2 changed files with 26 additions and 6 deletions

View File

@ -454,8 +454,10 @@ CREATE OR REPLACE VIEW \`sumy\` AS SELECT \`rozliczenie\`.\`wolontariuszID\` AS
return toSend; return toSend;
} }
function massEmail($emaile = [], $tytul = "Powiadomienie od sztabu", $tresc = "Brak treści wiadomości") function massEmail(emaile = [], tytul = "Powiadomienie od sztabu", tresc = "Brak treści wiadomości")
{ {
console.log('Wysyłanie maili do ' + emaile.length + ' osób');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
host: process.env.SMTPHOST, host: process.env.SMTPHOST,
@ -466,12 +468,12 @@ function massEmail($emaile = [], $tytul = "Powiadomienie od sztabu", $tresc = "B
pass: process.env.SMTPPASS pass: process.env.SMTPPASS
} }
}); });
$emaile.forEach(element => { emaile.forEach(element => {
const mailOptions = { const mailOptions = {
from: process.env.SMTPLOGIN, from: process.env.SMTPLOGIN,
bcc: element, bcc: element,
subject: $tytul, 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) 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){ transporter.sendMail(mailOptions, function(error, info){
if (error) { if (error) {
@ -483,6 +485,7 @@ function massEmail($emaile = [], $tytul = "Powiadomienie od sztabu", $tresc = "B
} }
}); });
}); });
return emaile.length;
} }

View File

@ -1732,7 +1732,7 @@ panelRouter.get('/wyslijEmaile', function(req, res) {
toReturn += '<h1>Wysyłanie emaili</h1>'; toReturn += '<h1>Wysyłanie emaili</h1>';
toReturn += '<form action="/panel/wyslijEmaile" method="POST">'; toReturn += '<form action="/panel/wyslijEmaile" method="POST">';
toReturn += '<table class="dane" style="width: 100%;">'; toReturn += '<table class="dane" style="width: 100%;">';
toReturn += '<tr><td>Temat</td><td><input type="text" name="temat"></td></tr>'; toReturn += '<tr><td>Temat</td><td><input type="text" name="temat" value="Powiadomienie od sztabu"></td></tr>';
toReturn += '<tr><td>Treść</td><td><div id="editor" style="min-height: 500px"></div><textarea name="tresc" style="display:none;"></textarea></td></tr>'; toReturn += '<tr><td>Treść</td><td><div id="editor" style="min-height: 500px"></div><textarea name="tresc" style="display:none;"></textarea></td></tr>';
toReturn += '</table>'; toReturn += '</table>';
toReturn += '<input type="submit" value="Wyślij">'; toReturn += '<input type="submit" value="Wyślij">';
@ -1757,7 +1757,24 @@ panelRouter.post('/wyslijEmaile', function(req, res) {
//pobierz temat i treść emaila, a potem bobierz wszystkie emaile (unikalne) i wyslij //pobierz temat i treść emaila, a potem bobierz wszystkie emaile (unikalne) i wyslij
var temat = req.body.temat; var temat = req.body.temat;
var tresc = req.body.tresc; var tresc = req.body.tresc;
res.send({temat: temat, tresc: tresc}); tresc = tresc.replace(/`/g, "'");
temat = temat.replace(/`/g, "'");
var emaileWolontariuszy = [];
con.query("SELECT DISTINCT `email` FROM `wolontariusz`", function(err, result) {
if (err) throw err;
result.forEach(function(row) {
emaileWolontariuszy.push(row.email);
});
var ile = massEmail(emaileWolontariuszy, temat, tresc);
var toReturn = headerHtml("Wysyłanie emaili");
toReturn += menuHtml(1);
toReturn += '<div class="content">';
toReturn += '<h1>Wysyłanie emaili</h1>';
toReturn += '<p>Wysłano ' + ile + ' emaili</p>';
toReturn += '</div>';
toReturn += footerHtml(1);
res.send(toReturn);
});
}); });
module.exports = panelRouter; module.exports = panelRouter;