From 564ee01f7fa77a1b3f768a2772447035f7233b21 Mon Sep 17 00:00:00 2001 From: kry008 Date: Fri, 3 Jan 2025 09:04:56 +0100 Subject: [PATCH] =?UTF-8?q?przygotowanie=20masowej=20wysy=C5=82ki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- serwer/app/func.js | 35 ++++++++++++++++++++++++++++++++++- serwer/app/panelRoutes.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/serwer/app/func.js b/serwer/app/func.js index 642d3bf..bcd08a1 100644 --- a/serwer/app/func.js +++ b/serwer/app/func.js @@ -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: '

' + $tytul + '


' + $tresc + '

Pozdrawiamy,
' + process.env.SZTAB + '

' + 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; @@ -465,4 +497,5 @@ exports.telefon = telefon; exports.sendToDiscord = sendToDiscord; exports.sendEmail = sendEmail; exports.checkSendEmail = checkSendEmail; -exports.baza = baza; \ No newline at end of file +exports.baza = baza; +exports.massEmail = massEmail; \ No newline at end of file diff --git a/serwer/app/panelRoutes.js b/serwer/app/panelRoutes.js index 4bede14..c5544a3 100644 --- a/serwer/app/panelRoutes.js +++ b/serwer/app/panelRoutes.js @@ -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 += '
'; + toReturn += '

Wysyłanie emaili

'; + toReturn += '
'; + toReturn += ''; + toReturn += ''; + toReturn += ''; + toReturn += '
Temat
Treść
'; + toReturn += ''; + toReturn += '
'; + toReturn += ''; + toReturn += ''; + toReturn += '