-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotificationEmail.js
More file actions
39 lines (34 loc) · 1000 Bytes
/
notificationEmail.js
File metadata and controls
39 lines (34 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require('dotenv');
const nodemailer = require('nodemailer');
const cron = require('node-cron');
const moment = require('moment');
const smtpTransporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'notifications.productized@gmail.com',
pass: process.env.NODEMAILER_PASS,
},
});
const sendNodemailer = (formData) => {
const mailOptions = {
from: 'Productized <notifications.productized@gmail.com>',
to: `${formData.emailsList}`,
subject: `${formData.subject}`,
text: `${formData.content}`,
};
const dateArray = formData.date.split(/[-T:]/).map(Number);
cron.schedule(
`${dateArray[4]} ${dateArray[3]} ${dateArray[2]} ${dateArray[1]} *`,
() => {
smtpTransporter.sendMail(mailOptions, (error, response) => {
if (error) {
console.log(error);
} else {
console.log(`Notification email sent!`);
}
smtpTransporter.close();
});
}
);
};
module.exports = sendNodemailer;