Skip to content

Commit

Permalink
Nodemailer
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Nov 7, 2023
1 parent 1dcecff commit acd3e52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions notifier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" <foo@example.com>`,
to: `"${readyJob.owner_name}" <${readyJob.owner_email}>`,
to: `"${jobData.owner_name}" <${jobData.owner_email}>`,
subject: `O flyer está pronto`,
html: `<a href="${readyJob.download_url}">Click to Download</a> <pre>${JSON.stringify(readyJob)}</pre>`,
html: `<a href="https://printer.carrismetropolitana.pt/download/${jobData._id}">Click to Download</a> <pre>${JSON.stringify(jobData)}</pre>`,
});

// 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}`);

//
}
Expand Down
8 changes: 4 additions & 4 deletions notifier/services/SMTPSERVICE.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}
Expand Down

0 comments on commit acd3e52

Please sign in to comment.