From 2bfc903fcb57e7704c3f01a5245f88eff657b7b3 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Wed, 28 Aug 2024 07:17:55 -0400 Subject: [PATCH] email sending --- app/assign_action.js | 104 +++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 23 deletions(-) diff --git a/app/assign_action.js b/app/assign_action.js index 83f9e5a..b16cc1e 100644 --- a/app/assign_action.js +++ b/app/assign_action.js @@ -3,34 +3,63 @@ const logger = require('../app/logger'); const fs = require('fs'); const nodemailer = require('nodemailer'); +const emailServer = process.env.WRENCHJOB_EMAIL_SERVER; +const emailServerPass = process.env.WRENCHJOB_EMAIL_PASS; var assign_action ={ - processLinedJobs(value) { + async processLinedJobs(value) { // const fs = require('fs'); - const file_name ="EMAIL//depend_job_added.html"; + // const file_name ="EMAIL//depend_job_added.html"; // fs.readFileSync(`${__dirname}\\FILENAME`); - fs.readFile(`${__dirname}/${file_name}`, 'utf8', (err, data) => { - if (err) { - console.error(err); - } - else - { - console.log(data); - } + // fs.readFile(`${__dirname}/${file_name}`, 'utf8', (err, data) => { + // if (err) { + // console.error(err); + // } + // else + // { + // console.log(data); + // } + // }); + /* + WRENCHJOB_EMAIL_SERVER='smtp.gmail.com' +WRENCHJOB_EMAIL_PORT='587' +WRENCHJOB_EMAIL_SECURE='false' +WRENCHJOB_EMAIL_USER='message@chiefsoft.com' +WRENCHJOB_EMAIL_PASS='may12002!' - const transporter = nodemailer.createTransport({ - service: "gmail", - host: "smtp.gmail.com", - port: 587, - secure: false, - auth: { - user: "message@chiefsoft.com", - pass: "may12002!", - }, - }); + */ + + // const mailMessage = this.parseEmailFile('depend_job_added'); + // const tempVal = this.getTemplateValues(mailMessage); + // const transporter = nodemailer.createTransport({ + // service: "gmail", + // host: "smtp.gmail.com", + // port: 587, + // secure: false, + // auth: { + // user: "message@chiefsoft.com", + // pass: "may12002!", + // }, + // }); + const emailSubject = "A similar task is available"; + + const mailMessage = this.parseEmailFile('depend_job_added'); + const tempVal = this.getTemplateValues(mailMessage); + const transporter = nodemailer.createTransport({ + service: "gmail", + host: `${emailServer}`, + port: 587, + secure: false, + auth: { + user: "message@chiefsoft.com", + pass: `${emailServerPass}`, + }, + }); + +// async function main() { // send mail with defined transport object @@ -38,16 +67,16 @@ var assign_action ={ from: '"Support ChiefSoft 👻" ', // sender address to: "ameye@chiefsoft.com", // list of receivers bcc: "ses66181@gmail.com", // list of receivers - subject: "Something good ✔", // Subject line + subject: `${emailSubject} ✔`, // Subject line text: "To Tester name", // plain text body - html: data, // html body + html: mailMessage, // html body }); console.log("Message sent: %s", info.messageId); // Message sent: } main().catch(console.error); - }); + // }); console.log(" processLinedJobs ************************ : ", value); if (value.depend_uid !== undefined && value.depend_uid.length > 10){ @@ -57,6 +86,35 @@ var assign_action ={ console.log("Thism is not a referenced job ***** : "); } }, + async parseEmailFile(emailFile){ + const file_name =`EMAIL//${emailFile}.html`; + // fs.readFileSync(`${__dirname}\\FILENAME`); + fs.readFile(`${__dirname}/${file_name}`, 'utf8', (err, data) => { + if (err) { + console.error(err); + return ''; + } + else + { + console.log(data); + // const tempVal = this.getTemplateValues(data); + return tempVal; + } + }) + }, + getTemplateValues(sentence){ + if(!sentence){ + return 'no sentence given' // RETURNS NOT FOUND IF NO SENSENCE WAS GIVEN + } + const regexToTest = /\{\{(.*?)\}\}/g; // EXPRESSION TO MATCH IN THE GIVEN SENTENCE + const regexForBrackets = /[\{{ |\}}]/g; // EXPRESSION TO ELIMINATE CURLY BRACKETS + const matches = sentence.match(regexToTest) // ARRAY OF MATCHED VALUES + if(matches && matches.length > 0){ + const returnedValues = matches.map(item => item.replace(regexForBrackets,'')) //STRIP OUT CURLY BRACKETS + return returnedValues + } + return 'no match found' + } };