- Nuovi Passi da completare: Leggere le Linee Guida e accettare le condizioni
- Aggiunti i Video e confermare di averli visti - In "La tua Lavagna" sono stati aggiunti come requisiti: (Accetto le Linee Guida e Vedo il Video di AYNI) - Aggiunto bottone "Invita Persone": apre la pagina dove c'è il messaggio da inviare alle persone. - La nuova pagina di registrazione https://test.gifteconomy.app/signup/paoloar77, comprende ora il testo delle Linee Guida + i Video, ed in fondo i campi per registrarsi.
This commit is contained in:
@@ -85,6 +85,8 @@ module.exports = {
|
||||
|
||||
const email = new Email(paramemail);
|
||||
|
||||
console.log(' *** Invia Email a ' + to);
|
||||
|
||||
return email
|
||||
.send({
|
||||
template: template,
|
||||
@@ -148,7 +150,7 @@ module.exports = {
|
||||
return strlinkreg;
|
||||
},
|
||||
getlinkRequestNewPassword: function (idapp, email, tokenforgot) {
|
||||
strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINK_UPDATE_PASSWORD + `?idapp=${idapp}&email=${email}&tokenforgot=${tokenforgot}`;
|
||||
strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINK_UPDATE_PASSWORD + `?idapp=${idapp}&email=${email}&tokenforgot=${tokenforgot}`;
|
||||
return strlinkreg;
|
||||
},
|
||||
sendEmail_Registration: async function (lang, emailto, user, idapp, idreg) {
|
||||
@@ -164,12 +166,12 @@ module.exports = {
|
||||
username: user.username,
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
forgetpwd: "",
|
||||
forgetpwd: tools.getHostByIdApp(idapp) + '/requestresetpwd',
|
||||
emailto: emailto,
|
||||
user,
|
||||
};
|
||||
|
||||
this.sendEmail_base('registration/' + lang, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
|
||||
this.sendEmail_base(tools.getpathregByIdApp(idapp, lang), emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
|
||||
|
||||
// Send to the Admin an Email
|
||||
this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
|
||||
@@ -411,10 +413,13 @@ module.exports = {
|
||||
},
|
||||
|
||||
replacefields: function (mylocalsconf) {
|
||||
|
||||
mylocalsconf.dataemail.disclaimer_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer);
|
||||
mylocalsconf.dataemail.disc_bottom_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom);
|
||||
mylocalsconf.dataemail.templ.testoheadermail_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail);
|
||||
try {
|
||||
mylocalsconf.dataemail.disclaimer_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer);
|
||||
mylocalsconf.dataemail.disc_bottom_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom);
|
||||
mylocalsconf.dataemail.templ.testoheadermail_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail);
|
||||
} catch (e) {
|
||||
console.error('Error replacefields: ' + e)
|
||||
}
|
||||
|
||||
return mylocalsconf
|
||||
},
|
||||
@@ -445,7 +450,7 @@ module.exports = {
|
||||
};
|
||||
|
||||
// console.log(mydata.templemail_id);
|
||||
mydata.templ = await TemplEmail.findOne({_id: mydata.templemail_id });
|
||||
mydata.templ = await TemplEmail.findOne({ _id: mydata.templemail_id });
|
||||
// console.log(mydata.templ);
|
||||
|
||||
return mydata
|
||||
@@ -487,7 +492,10 @@ module.exports = {
|
||||
|
||||
sendEmail_Newsletter_Events: async function (lang, idapp, id_newstosent) {
|
||||
|
||||
console.log('INIZIO - sendEmail_Newsletter_Events', tools.getNomeAppByIdApp(idapp));
|
||||
const msginizio = 'INIZIO - sendEmail_Newsletter_Events: ' + tools.getNomeAppByIdApp(idapp);
|
||||
console.log(msginizio);
|
||||
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
||||
|
||||
//++Todo Extract List Email to send
|
||||
const userstosend = await MailingList.findAllIdAppSubscribed(idapp);
|
||||
@@ -507,76 +515,108 @@ module.exports = {
|
||||
|
||||
const mynewsrec = await Newstosent.findOne({ _id: id_newstosent });
|
||||
|
||||
mynewsrec.numemail_tot = userstosend.length;
|
||||
mynewsrec.templemail_str = mylocalsconf.dataemail.templ.subject;
|
||||
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
|
||||
try {
|
||||
mynewsrec.numemail_tot = userstosend.length;
|
||||
mynewsrec.templemail_str = mylocalsconf.dataemail.templ.subject;
|
||||
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
|
||||
|
||||
const smtpTransport = this.getTransport(mylocalsconf);
|
||||
const smtpTransport = this.getTransport(mylocalsconf);
|
||||
|
||||
// LOOP USERS EMAIL
|
||||
for (const user of userstosend) {
|
||||
// LOOP USERS EMAIL
|
||||
for (const user of userstosend) {
|
||||
|
||||
const isok = await MailingList.isOk(idapp, user._id, id_newstosent);
|
||||
if (isok) {
|
||||
let secpause = await Settings.getValDbSettings(idapp, 'MSEC_PAUSE_SEND', process.env.DELAY_SENDEMAIL);
|
||||
if (secpause < process.env.DELAY_SENDEMAIL)
|
||||
secpause = process.env.DELAY_SENDEMAIL;
|
||||
try {
|
||||
|
||||
activate = await Newstosent.isActivated(id_newstosent);
|
||||
const isok = await MailingList.isOk(idapp, user._id, id_newstosent);
|
||||
if (isok) {
|
||||
let secpause = await Settings.getValDbSettings(idapp, 'MSEC_PAUSE_SEND', process.env.DELAY_SENDEMAIL);
|
||||
if (secpause < process.env.DELAY_SENDEMAIL)
|
||||
secpause = process.env.DELAY_SENDEMAIL;
|
||||
|
||||
if (!activate) {
|
||||
// Invio Newsletter Abortito!
|
||||
mynewsrec.error_job = 'Invio Newsletter abortito alle ore ' + new Date().toDateString() + new Date().toTimeString();
|
||||
await mynewsrec.save();
|
||||
await Newstosent.processingJob(id_newstosent, false);
|
||||
console.log('*** L\'Invio della Newsletter è stato fermato ! ');
|
||||
return false
|
||||
activate = await Newstosent.isActivated(id_newstosent);
|
||||
|
||||
if (!activate) {
|
||||
// Invio Newsletter Abortito!
|
||||
mynewsrec.error_job = 'Invio Newsletter abortito alle ore ' + new Date().toDateString() + new Date().toTimeString();
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, mynewsrec.error_job);
|
||||
await mynewsrec.save();
|
||||
await Newstosent.processingJob(id_newstosent, false);
|
||||
console.log('*** L\'Invio della Newsletter è stato fermato ! ');
|
||||
return false
|
||||
}
|
||||
|
||||
mylocalsconf.name = user.name;
|
||||
mylocalsconf.surname = user.surname;
|
||||
mylocalsconf.emailto = user.email;
|
||||
mylocalsconf.hashemail = tools.getHash(user.email);
|
||||
|
||||
mylocalsconf = this.replacefields(mylocalsconf);
|
||||
|
||||
|
||||
// If has already sent, don't send it again!
|
||||
if (user.lastid_newstosent !== id_newstosent.toString()) {
|
||||
// console.log('@@@@@ COMPARE DIVERSI: lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
|
||||
|
||||
if (process.env.DEBUG)
|
||||
await tools.snooze(5000);
|
||||
|
||||
// Send Email to the User
|
||||
// console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
|
||||
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport);
|
||||
|
||||
if ((mynewsrec.numemail_sent % 50) === 0) {
|
||||
const msgproc = 'In Corso ' + mynewsrec.numemail_sent + ' / ' + mynewsrec.numemail_tot + ' Email inviate...';
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, msgproc);
|
||||
}
|
||||
|
||||
//Put the result in the database, to check if is sent or not.
|
||||
const updateml = await MailingList.findOneAndUpdate({
|
||||
idapp,
|
||||
email: user.email
|
||||
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
|
||||
|
||||
|
||||
//Delay for send email...
|
||||
await tools.snooze(secpause);
|
||||
|
||||
mynewsrec.lastemailsent_Job = new Date();
|
||||
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
|
||||
|
||||
const recsaved = await mynewsrec.save();
|
||||
} else {
|
||||
console.log('*** COMPARE: UGUALI !!!!! lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
const msgerr = 'Error LOOP sendEmail_Newsletter_Events: ' + e;
|
||||
console.error(msgerr);
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, msgerr);
|
||||
}
|
||||
}
|
||||
|
||||
mylocalsconf.name = user.name;
|
||||
mylocalsconf.surname = user.surname;
|
||||
mylocalsconf.emailto = user.email;
|
||||
mylocalsconf.hashemail = tools.getHash(user.email);
|
||||
await Newstosent.endJob(id_newstosent);
|
||||
await Newstosent.processingJob(id_newstosent, false);
|
||||
let msgfine = 'FINE - sendEmail_Newsletter_Events [' + tools.getNomeAppByIdApp(idapp) + ']: ';
|
||||
msgfine += mynewsrec.numemail_sent + ' Email inviate';
|
||||
console.log(msgfine);
|
||||
|
||||
mylocalsconf = this.replacefields(mylocalsconf);
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, msgfine);
|
||||
|
||||
} catch (e) {
|
||||
|
||||
// If has already sent, don't send it again!
|
||||
if (user.lastid_newstosent !== id_newstosent.toString()) {
|
||||
console.log('@@@@@ COMPARE DIVERSI: lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
|
||||
activate = await Newstosent.isActivated(id_newstosent);
|
||||
|
||||
if (process.env.DEBUG)
|
||||
await tools.snooze(5000);
|
||||
|
||||
// Send Email to the User
|
||||
// console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
|
||||
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({
|
||||
idapp,
|
||||
email: user.email
|
||||
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
|
||||
|
||||
|
||||
//Delay for send email...
|
||||
await tools.snooze(secpause);
|
||||
|
||||
mynewsrec.lastemailsent_Job = new Date();
|
||||
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
|
||||
|
||||
const recsaved = await mynewsrec.save();
|
||||
} else {
|
||||
console.log('*** COMPARE: UGUALI !!!!! lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
|
||||
}
|
||||
if (!activate) {
|
||||
// Invio Newsletter Abortito!
|
||||
mynewsrec.error_job = 'Invio Newsletter abortito alle ore ' + new Date().toDateString() + new Date().toTimeString();
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, mynewsrec.error_job);
|
||||
await mynewsrec.save();
|
||||
await Newstosent.processingJob(id_newstosent, false);
|
||||
console.log('*** L\'Invio della Newsletter è stato fermato ! ');
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
await Newstosent.endJob(id_newstosent);
|
||||
await Newstosent.processingJob(id_newstosent, false);
|
||||
console.log('****', tools.getNomeAppByIdApp(idapp), mynewsrec.numemail_sent, 'Email inviate');
|
||||
|
||||
console.log('FINE (esco da funz) - sendEmail_Newsletter_Events', tools.getNomeAppByIdApp(idapp));
|
||||
|
||||
},
|
||||
|
||||
@@ -597,11 +637,11 @@ module.exports = {
|
||||
|
||||
return Newstosent.findNewsletterPending_To_Send(idapp)
|
||||
.then((rec) => { //
|
||||
this.sendNewsletter(rec)
|
||||
this.sendNewsletter(rec, idapp)
|
||||
});
|
||||
},
|
||||
|
||||
sendNewsletter: async function (rec) {
|
||||
sendNewsletter: async function (rec, idapp) {
|
||||
if (rec) {
|
||||
// Start the job
|
||||
myjobnews = await Newstosent.findOne({ _id: rec._id });
|
||||
@@ -612,7 +652,7 @@ module.exports = {
|
||||
myjobnews.save()
|
||||
.then((ris) => {
|
||||
|
||||
this.sendEmail_Newsletter_Events("it", '2', rec._id);
|
||||
this.sendEmail_Newsletter_Events("it", idapp, rec._id);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user