-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheod
executable file
·62 lines (53 loc) · 1.45 KB
/
eod
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
require('dotenv').config({ path: (__dirname + '/.env') });
var nodemailer = require("nodemailer"),
moment = require('moment'),
fs = require('fs'),
path = require('path'),
CronJob = require('cron').CronJob;
Mailer = {
transporter: function(){
return nodemailer.createTransport({
service: 'Gmail',
auth: {
user: process.env.USER_EMAIL,
pass: process.env.USER_PASS
}
})
},
emailText: function(){
var greeting = 'Greetings, ' + process.env.RECIPIENT_NAME + ".\n\nThis is an automated email. Here is what I did today:\n\n";
return greeting + fs.readFileSync(path.resolve(__dirname + '/today.txt'));
},
mailOptions: function(){
var _self = this;
return {
from: process.env.SENDER_NAME + ' <' + process.env.USER_EMAIL + '>',
to: process.env.RECIPIENT_EMAIL,
cc: process.env.USER_EMAIL,
subject: 'EOD email: ' + moment().format('dddd, MMMM Do, YYYY'),
text: _self.emailText()
}
},
sendMail: function(){
var transporter = this.transporter();
transporter.sendMail(this.mailOptions(), function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
}
var CronRunner = {
run: function(){
var job = new CronJob({
cronTime: '30 17 * * 1-5',
onTick: function() {
Mailer.sendMail()
},
start: true,
});
}
}
CronRunner.run();