From acd3e5285541539b831c23446a63c17b683e6466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20de=20Vasconcelos?= Date: Tue, 7 Nov 2023 22:25:09 +0000 Subject: [PATCH] Nodemailer --- .../JobsExplorerCreate/JobsExplorerCreate.js | 2 +- notifier/index.js | 10 +++++----- notifier/services/SMTPSERVICE.js | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manager/components/JobsExplorerCreate/JobsExplorerCreate.js b/manager/components/JobsExplorerCreate/JobsExplorerCreate.js index 0bcf653..66e94d2 100644 --- a/manager/components/JobsExplorerCreate/JobsExplorerCreate.js +++ b/manager/components/JobsExplorerCreate/JobsExplorerCreate.js @@ -26,7 +26,7 @@ export default function JobsExplorerCreate() { method: 'POST', body: JSON.stringify({ owner_name: 'Teste', - owner_email: 'test@email.com', + owner_email: 'johnyvasconcelos@icloud.com', owner_lang: 'pt', gdpr_consent: true, print_host: 'escolas.carrismetropolitana.pt', diff --git a/notifier/index.js b/notifier/index.js index 0482339..9d3bfad 100644 --- a/notifier/index.js +++ b/notifier/index.js @@ -36,22 +36,22 @@ const RUN_INTERVAL = 30000; // seconds const allReadyJobs = await QUEUEDB.Job.find({ status: 'ready' }).toArray(); // Iterate on each ready job to notify its owner - for (const readyJob of allReadyJobs) { + for (const jobData of allReadyJobs) { // // Send an email to the owner await SMTPSERVICE.transport.sendMail({ from: `"Carris Metropolitana" `, - to: `"${readyJob.owner_name}" <${readyJob.owner_email}>`, + to: `"${jobData.owner_name}" <${jobData.owner_email}>`, subject: `O flyer está pronto`, - html: `Click to Download
${JSON.stringify(readyJob)}
`, + html: `Click to Download
${JSON.stringify(jobData)}
`, }); // Update status of this job - await QUEUEDB.Job.updateOne({ _id: readyJob._id }, { status: 'waiting_download', date_notified: new Date().toISOString() }); + await QUEUEDB.Job.updateOne({ _id: jobData._id }, { status: 'waiting_download', date_notified: new Date().toISOString() }); // Log progress - console.log(`→ id: ${readyJob._id} | owner_email: ${readyJob.owner_email}`); + console.log(`→ id: ${jobData._id} | owner_email: ${jobData.owner_email}`); // } diff --git a/notifier/services/SMTPSERVICE.js b/notifier/services/SMTPSERVICE.js index e272843..62fee3f 100644 --- a/notifier/services/SMTPSERVICE.js +++ b/notifier/services/SMTPSERVICE.js @@ -7,12 +7,12 @@ const nodemailer = require('nodemailer'); class SMTPSERVICE { constructor() { this.transport = nodemailer.createTransport({ - host: 'smtp.forwardemail.net', - port: 465, + host: process.env.EMAIL_SERVER_HOST, + port: process.env.EMAIL_SERVER_PORT, secure: true, auth: { - user: 'REPLACE-WITH-YOUR-ALIAS@YOURDOMAIN.COM', - pass: 'REPLACE-WITH-YOUR-GENERATED-PASSWORD', + user: process.env.EMAIL_SERVER_USER, + pass: process.env.EMAIL_SERVER_PASSWORD, }, }); }