-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.61 KB
/
index.js
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
40
41
42
43
44
45
46
47
const cron = require('node-cron');
const express = require('express');
const nodeMailer = require('nodemailer');
const SMTPTransport = require('nodemailer/lib/smtp-transport');
const app = express();
let testAccount = nodeMailer.createTestAccount((err) => {
if(err) {
console.error('Failed to create test account. ' + err.message)
return process.exit(1);
}
console.log('Credentials obtained, sending message...')
});
cron.schedule("* * * * *", async () => {
console.log('Running cron job');
let transporter = nodeMailer.createTransport(new SMTPTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.spass // generated ethereal password
},
tls: {
rejectUnauthorized: false
},
sendMail : true
}));
const mailOptions = {
from: '"John Doe" <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: 'Hello there!', // Subject line
// text: 'A Message from Node Cron App', // plain text body
html: '<b>A Message from Node Cron App</b>' // html body
};
transporter.sendMail(mailOptions).then(info => {
console.log(info.id);
console.log(nodeMailer.getTestMessageUrl);
}).catch(error => console.log(error));
});
let port = process.env.PORT || 8000;
app.listen(port, () => console.log(`Server run on port::${port}`));