- Sending Newsletter, others settings.
This commit is contained in:
@@ -1 +1 @@
|
||||
=`Newsletter `
|
||||
=`${dataemail.templ.subject}`
|
||||
|
||||
@@ -8,6 +8,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const { Settings } = require('./settings');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
@@ -113,13 +115,13 @@ MyEventSchema.statics.findAllIdApp = function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
MyEventSchema.statics.getLastEvents = function (idapp) {
|
||||
MyEventSchema.statics.getLastEvents = async function (idapp) {
|
||||
const Event = this;
|
||||
|
||||
const lastn = 3;
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_EV', 1);
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $match: { idapp, dateTimeStart: { $gte: tools.IncDateNow(- 1000 * 60 * 60 * 24) } } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'operators',
|
||||
@@ -152,7 +154,11 @@ MyEventSchema.statics.getLastEvents = function (idapp) {
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
// console.table(arrrec);
|
||||
return arrrec.slice(-lastn)
|
||||
if (lastn > 0) {
|
||||
return arrrec.slice(0, lastn);
|
||||
} else {
|
||||
return arrrec
|
||||
}
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ SettingsSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
SettingsSchema.statics.getValDbSettings = function (idapp, key) {
|
||||
SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
|
||||
return Settings.findOne({ idapp, key })
|
||||
.then((myrec) => {
|
||||
// console.log('getValDbSettings', myrec, 'idapp', idapp);
|
||||
@@ -63,12 +63,12 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key) {
|
||||
else
|
||||
return myrec.value_str;
|
||||
} else {
|
||||
return ''
|
||||
return def
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
console.error('getValDbSettings', err);
|
||||
return null;
|
||||
return def;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -37,6 +37,9 @@ module.exports = {
|
||||
|
||||
// console.log("check EMAIL :" + checkifSendEmail());
|
||||
|
||||
if (replyTo === '')
|
||||
replyTo = mylocalsconf.dataemail.email_reply;
|
||||
|
||||
const paramemail = {
|
||||
message: {
|
||||
from: mylocalsconf.dataemail.from, // sender address
|
||||
@@ -66,7 +69,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('paramemail', paramemail);
|
||||
// console.log('paramemail', paramemail);
|
||||
|
||||
const email = new Email(paramemail);
|
||||
|
||||
@@ -79,6 +82,7 @@ module.exports = {
|
||||
locals: mylocalsconf,
|
||||
})
|
||||
.then((ris) => {
|
||||
console.log('ris EMAIL', ris);
|
||||
return !!ris
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -408,6 +412,7 @@ module.exports = {
|
||||
disc_title: await Settings.getValDbSettings(idapp, 'DISC_TITLE'),
|
||||
height_logo: await Settings.getValDbSettings(idapp, 'HEIGHT_LOGO'),
|
||||
from: await Settings.getValDbSettings(idapp, 'EMAIL_FROM'),
|
||||
email_reply: await Settings.getValDbSettings(idapp, 'EMAIL_REPLY', ''),
|
||||
pwd_from: await Settings.getValDbSettings(idapp, 'PWD_FROM'),
|
||||
email_service: await Settings.getValDbSettings(idapp, 'EMAIL_SERVICE_SEND'),
|
||||
email_port: await Settings.getValDbSettings(idapp, 'EMAIL_PORT'),
|
||||
@@ -481,11 +486,15 @@ module.exports = {
|
||||
|
||||
const smtpTransport = this.getTransport();
|
||||
|
||||
let secpause = await Settings.getValDbSettings(idapp, 'MSEC_PAUSE_SEND', process.env.DELAY_SENDEMAIL);
|
||||
if (secpause > process.env.DELAY_SENDEMAIL)
|
||||
secpause = process.env.DELAY_SENDEMAIL;
|
||||
|
||||
// LOOP USERS EMAIL
|
||||
for (const user of userstosend) {
|
||||
|
||||
if (process.env.DEBUG)
|
||||
await tools.snooze(10000);
|
||||
await tools.snooze(30000);
|
||||
|
||||
activate = await Newstosent.isActivated(id_newstosent);
|
||||
|
||||
@@ -508,7 +517,7 @@ module.exports = {
|
||||
if (user.lastid_newstosent !== id_newstosent.toString()) {
|
||||
// Send Email to the User
|
||||
console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
|
||||
const esito = this.sendEmail_base('newsletter/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '', smtpTransport);
|
||||
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport);
|
||||
|
||||
//Put the result in the database, to check if is sent or not.
|
||||
const updateml = await MailingList.findOneAndUpdate({
|
||||
@@ -518,7 +527,7 @@ module.exports = {
|
||||
|
||||
|
||||
//Delay for send email...
|
||||
await tools.snooze(process.env.DELAY_SENDEMAIL);
|
||||
await tools.snooze(secpause);
|
||||
|
||||
|
||||
mynewsrec.lastemailsent_Job = new Date();
|
||||
@@ -597,6 +606,9 @@ module.exports = {
|
||||
hashemail: tools.getHash(myemail),
|
||||
};
|
||||
|
||||
console.log('myarrevents');
|
||||
console.table(mylocalsconf.arrevents);
|
||||
|
||||
mylocalsconf.dataemail = await this.getdataemail(idapp);
|
||||
|
||||
this.replacefields(mylocalsconf);
|
||||
@@ -604,7 +616,7 @@ module.exports = {
|
||||
const smtpTransport = this.getTransport();
|
||||
|
||||
console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly', previewonly);
|
||||
return this.sendEmail_base('newsletter/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '', smtpTransport, previewonly);
|
||||
return this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, '', smtpTransport, previewonly);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -230,8 +230,8 @@ function testmsgwebpush() {
|
||||
|
||||
}
|
||||
|
||||
// Cron every 5 minutes
|
||||
cron.schedule('*/5 * * * *', () => {
|
||||
// Cron every X minutes
|
||||
cron.schedule('*/2 * * * *', () => {
|
||||
console.log('Running Cron Job');
|
||||
mycron();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user