email sending

This commit is contained in:
CHIEFSOFT\ameye
2024-08-28 07:17:55 -04:00
parent 38046aa550
commit 2bfc903fcb
+81 -23
View File
@@ -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 👻" <message@chiefsoft.com>', // 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: <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){
@@ -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'
}
};