151 lines
5.5 KiB
JavaScript
151 lines
5.5 KiB
JavaScript
const db = require('../app/db')
|
|
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 ={
|
|
|
|
async processLinedJobs(value) {
|
|
// const fs = require('fs');
|
|
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);
|
|
// }
|
|
// });
|
|
/*
|
|
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 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";
|
|
// console.log("HERE -- 00001***********************************************");
|
|
// const mailMessage = await this.parseEmailFile('depend_job_added');
|
|
//
|
|
// console.log("HERE -- 00001aaa => mailMessage ==>",mailMessage,"==============0000==================");
|
|
//
|
|
//
|
|
// await this.parseEmailFile('depend_job_added').then((mailMessage)=>{
|
|
// console.log("HERE -- 00002***********************************************", mailMessage);
|
|
// const tempVal = this.getTemplateValues(mailMessage);
|
|
// console.log("MATCHED VALUES =>", tempVal);
|
|
// console.log("HERE -- 00003***********************************************");
|
|
//
|
|
// });
|
|
fs.readFile(`${__dirname}/${file_name}`, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
}
|
|
else
|
|
{
|
|
console.log(data);
|
|
const transporter = nodemailer.createTransport({
|
|
service: "gmail",
|
|
host: `${emailServer}`,
|
|
port: 587,
|
|
secure: false,
|
|
auth: {
|
|
user: "message@chiefsoft.com",
|
|
pass: `${emailServerPass}`,
|
|
},
|
|
});
|
|
|
|
//
|
|
|
|
const tempVal = this.getTemplateValues(data);
|
|
console.log("MATCHED VALUES =>", tempVal);
|
|
console.log("HERE -- 00003***********************************************");
|
|
|
|
|
|
async function main() {
|
|
// send mail with defined transport object
|
|
const info = await transporter.sendMail({
|
|
from: '"Support ChiefSoft 👻" <message@chiefsoft.com>', // sender address
|
|
to: "ameye@chiefsoft.com", // list of receivers
|
|
bcc: "ses66181@gmail.com", // list of receivers
|
|
subject: `${emailSubject} ✔`, // Subject line
|
|
text: "To Tester name", // plain text body
|
|
html: data, // html body
|
|
});
|
|
console.log("Message sent: %s", info.messageId);
|
|
// Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
|
|
}
|
|
main().catch(console.error);
|
|
}
|
|
});
|
|
|
|
|
|
console.log(" processLinedJobs ************************ : ", value);
|
|
if (value.depend_uid !== undefined && value.depend_uid.length > 10){
|
|
console.log("We need contact people that did this job: ", value.depend_uid);
|
|
}
|
|
else{
|
|
console.log("Thism is not a referenced job ***** : ");
|
|
}
|
|
},
|
|
async parseEmailFile(emailFile){
|
|
const file_name =`EMAIL//${emailFile}.html`;
|
|
// fs.readFileSync(`${__dirname}\\FILENAME`);
|
|
await fs.readFile(`${__dirname}/${file_name}`, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
return '';
|
|
}
|
|
else
|
|
{
|
|
console.log(data);
|
|
return data;
|
|
}
|
|
})
|
|
return '';
|
|
},
|
|
getTemplateValues(sentence){
|
|
if(!sentence){
|
|
return 'no sentence given' // RETURNS NOT FOUND IF NO SENSENCE WAS GIVEN
|
|
}
|
|
|
|
try {
|
|
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 [];
|
|
} catch (error) {
|
|
console.error(error);
|
|
return [];
|
|
}
|
|
|
|
|
|
}
|
|
};
|
|
|
|
module.exports = assign_action; |