alseambusher
8 years ago
4 changed files with 56 additions and 54 deletions
@ -1,36 +1,19 @@ |
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var defaults = require("../config/mailconfig.js"); |
var defaults = require("../config/mailconfig.js"); |
||||||
|
var crontab = require("../crontab.js"); |
||||||
var nodemailer = require('nodemailer'); |
var nodemailer = require('nodemailer'); |
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
crontab.get_crontab(process.argv[process.argv.length -1 -2], function(job){ |
||||||
var transporter = nodemailer.createTransport(defaults.transporterStr); |
var transporter = nodemailer.createTransport(job.mailing.transporterStr); |
||||||
var mailOptions = defaults.mailOptions; |
var mailOptions = job.mailing.mailOptions; |
||||||
|
|
||||||
var stdin = process.stdin, |
|
||||||
stdout = process.stdout, |
|
||||||
inputChunks = []; |
|
||||||
|
|
||||||
stdin.resume(); |
mailOptions.attachments = [{filename: "stdout.txt", path: process.argv[process.argv.length -1 -1]}, {filename: "stderr.txt", path: process.argv[process.argv.length -1]}]; |
||||||
stdin.setEncoding('utf8'); |
|
||||||
|
|
||||||
stdin.on('data', function (chunk) { |
|
||||||
inputChunks.push(chunk); |
|
||||||
}); |
|
||||||
|
|
||||||
stdin.on('end', function () { |
|
||||||
var inputJSON = inputChunks.join(), |
|
||||||
mailOptions = JSON.parse(inputJSON); |
|
||||||
|
|
||||||
// outputJSON = JSON.stringify(parsedData, null, ' ');
|
|
||||||
// stdout.write(outputJSON);
|
|
||||||
// stdout.write('\n');
|
|
||||||
}); |
|
||||||
|
|
||||||
transporter.sendMail(mailOptions, function(error, info){ |
transporter.sendMail(mailOptions, function(error, info){ |
||||||
if(error){ |
if(error){ |
||||||
return console.log(error); |
return console.log(error); |
||||||
} |
} |
||||||
console.log('Message sent: ' + info.response); |
console.log('Message sent: ' + info.response); |
||||||
|
}); |
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue