Add basic email functionality w/nodemailer.
This commit is contained in:
parent
92bba362ad
commit
1aadb08db0
@ -5,7 +5,8 @@
|
|||||||
"body-parser": "^1.12.4",
|
"body-parser": "^1.12.4",
|
||||||
"express": "^4.12.4",
|
"express": "^4.12.4",
|
||||||
"sqlite3": "^3.0.8",
|
"sqlite3": "^3.0.8",
|
||||||
"express-hbs": "^0.8.4"
|
"express-hbs": "^0.8.4",
|
||||||
|
"nodemailer": "^1.3.4"
|
||||||
},
|
},
|
||||||
"scripts": { "start": "node server.js" }
|
"scripts": { "start": "node server.js" }
|
||||||
}
|
}
|
||||||
|
25
server.js
25
server.js
@ -1,10 +1,26 @@
|
|||||||
var express = require("express");
|
var express = require("express");
|
||||||
var hbs = require('express-hbs');
|
var hbs = require('express-hbs');
|
||||||
|
var nodemailer = require('nodemailer');
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var app = express();
|
var app = express();
|
||||||
var logfile = fs.createWriteStream('./db/log.log', {flags: 'a'});
|
var logfile = fs.createWriteStream('./db/log.log', {flags: 'a'});
|
||||||
|
|
||||||
|
// Setup email
|
||||||
|
var transporter = nodemailer.createTransport({
|
||||||
|
service: 'Gmail',
|
||||||
|
auth: {
|
||||||
|
user: 'jkU8K5lrog9w@gmail.com',
|
||||||
|
pass: 'NSLQZ~d6Zb~LLv8#t'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var mailOptions = {
|
||||||
|
from: 'Alert Monitor <jkU8K5lrog9w@gmail.com>',
|
||||||
|
to: 'jody@kaplon.us',
|
||||||
|
subject: 'Alert received',
|
||||||
|
text: 'test alert'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var file = "./db/test.db";
|
var file = "./db/test.db";
|
||||||
var exists = fs.existsSync(file);
|
var exists = fs.existsSync(file);
|
||||||
@ -42,7 +58,7 @@ app.get('/', function(req, res){
|
|||||||
//res.sendFile("/usr/src/app/index.html");
|
//res.sendFile("/usr/src/app/index.html");
|
||||||
//fs.createReadStream('./log.log').pipe(res);
|
//fs.createReadStream('./log.log').pipe(res);
|
||||||
console.log("got a GET request...");
|
console.log("got a GET request...");
|
||||||
db.all("SELECT coreId, published_at FROM Alerts", function(err, rows){
|
db.all("SELECT coreId, published_at FROM Alerts ORDER BY published_at DESC LIMIT 30;", function(err, rows){
|
||||||
console.log(rows);
|
console.log(rows);
|
||||||
res.render('home', {alerts: rows}, function(err, html) {
|
res.render('home', {alerts: rows}, function(err, html) {
|
||||||
res.send(html);
|
res.send(html);
|
||||||
@ -64,6 +80,13 @@ app.post('/', function(req, res){
|
|||||||
JSON.stringify(req.body.published_at, null, 4)
|
JSON.stringify(req.body.published_at, null, 4)
|
||||||
);
|
);
|
||||||
stmt.finalize();
|
stmt.finalize();
|
||||||
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
|
if(error){
|
||||||
|
console.log(error);
|
||||||
|
}else{
|
||||||
|
console.log('Message sent: ' + info.response);
|
||||||
|
}
|
||||||
|
});
|
||||||
//res.send(JSON.stringify(req.body, null, 4));
|
//res.send(JSON.stringify(req.body, null, 4));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user