Enable email setup, even though most email code still commented out; at least server still runs.
This commit is contained in:
parent
17a701ea5f
commit
31a7cc6517
56
server.js
56
server.js
@ -1,7 +1,7 @@
|
||||
var express = require("express");
|
||||
var hbs = require('express-hbs');
|
||||
require('handlebars-form-helpers').register(hbs.handlebars);
|
||||
//var nodemailer = require('nodemailer');
|
||||
var nodemailer = require('nodemailer');
|
||||
var courtsopenUtils = require('./courtsopenUtils.js');
|
||||
var fs = require("fs");
|
||||
var bodyParser = require("body-parser");
|
||||
@ -9,20 +9,19 @@ var app = express();
|
||||
var logfile = fs.createWriteStream('./db/log.log', {flags: 'a'});
|
||||
|
||||
// Setup email
|
||||
//var transporter = nodemailer.createTransport({
|
||||
//service: 'Gmail',
|
||||
//auth: {
|
||||
//user: 'alertmonitorfl@gmail.com',
|
||||
//pass: '6g*hkvVc%91oo3#$'
|
||||
//}
|
||||
//});
|
||||
//var mailOptions = {
|
||||
//from: 'Alert Monitor <alertmonitorfl@gmail.com>',
|
||||
var transporter = nodemailer.createTransport({
|
||||
service: 'Gmail',
|
||||
auth: {
|
||||
user: 'alertmonitorfl@gmail.com',
|
||||
pass: '6g*hkvVc%91oo3#$'
|
||||
}
|
||||
});
|
||||
var mailOptions = {
|
||||
from: 'Alert Monitor <alertmonitorfl@gmail.com>',
|
||||
//to: 'jody@kaplon.us,don@gettner.com',
|
||||
//subject: 'Alert received',
|
||||
//text: 'test alert' // Get custom text later on email generation.
|
||||
//};
|
||||
|
||||
to: 'jody@kaplon.us',
|
||||
subject: 'Device did not wish me a GoodMorning or GoodEvening',
|
||||
};
|
||||
|
||||
var file = "./db/courtsopen.db";
|
||||
var exists = fs.existsSync(file);
|
||||
@ -116,19 +115,18 @@ app.post('/', function(req, res){
|
||||
status
|
||||
);
|
||||
stmt.finalize();
|
||||
});
|
||||
|
||||
// Send emails on alerts only
|
||||
//if(status.toLowerCase().indexOf('alert') > -1){
|
||||
//mailOptions.text = 'An alert message was received: \n\n';
|
||||
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
||||
//mailOptions.text = mailOptions.text + 'Published at, ' + courtsopenUtils.getLocDateFromUTC(pubAt) + ' ' + courtsopenUtils.getLocTimeFromUTC(pubAt) + '\n';
|
||||
//mailOptions.text = mailOptions.text + 'From device, ' + courtsopenUtils.getCoreNameFromCoreId(db, coreid) + '\n';
|
||||
//var nameQry = 'SELECT coreName FROM Cores WHERE coreId = ?;'
|
||||
//db.get(nameQry, coreid, function(err, row){
|
||||
//if ((err) || (typeof row == undefined)) {
|
||||
// Don't care about this error or empty result set, still need to send email.
|
||||
//row.coreName = '# No Name #';
|
||||
//}
|
||||
setInterval(function() {
|
||||
// Check every hour to see if GoodMorning or GoodEvening has gone missing.
|
||||
var deadManQry = "select published_at from Alerts where datetime(published_at) > datetime('now', '-14.5 hours') order by datetime(published_at) limit 1";
|
||||
//db.get(deadManQry, function(err, row){
|
||||
//if (err !== null) { console.log(err); }
|
||||
//else if (typeof row == undefined) {
|
||||
//mailOptions.text = 'An alert message was received: \n\n';
|
||||
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
||||
//mailOptions.text = mailOptions.text + 'Published at, ' + courtsopenUtils.getLocDateFromUTC(pubAt) + ' ' + courtsopenUtils.getLocTimeFromUTC(pubAt) + '\n';
|
||||
//mailOptions.text = mailOptions.text + 'From device, ' + courtsopenUtils.getCoreNameFromCoreId(db, coreid) + '\n';
|
||||
//mailOptions.text = mailOptions.text + 'From device, ' + row.coreName + '\n';
|
||||
|
||||
//transporter.sendMail(mailOptions, function(error, info){
|
||||
@ -138,10 +136,8 @@ app.post('/', function(req, res){
|
||||
//console.log('Message sent: ' + info.response);
|
||||
//}
|
||||
//});
|
||||
//});
|
||||
//}
|
||||
//res.send(JSON.stringify(req.body, null, 4));
|
||||
});
|
||||
//}
|
||||
}, 60000);
|
||||
|
||||
app.listen(3000, function() {
|
||||
console.log("Started on PORT 3000");
|
||||
|
Loading…
Reference in New Issue
Block a user