2012-04-05 05:21:56 +00:00
|
|
|
var express = require('express')
|
|
|
|
, app = express.createServer()
|
|
|
|
, nodemailer = require('nodemailer')
|
|
|
|
|
|
|
|
// Express config
|
|
|
|
app.set('views', __dirname + '/views');
|
|
|
|
app.set('view engine', 'jade');
|
|
|
|
|
|
|
|
app.use(express.cookieParser());
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
app.use(express.bodyParser());
|
|
|
|
|
2012-04-05 07:30:47 +00:00
|
|
|
var config = {
|
|
|
|
aws: {
|
|
|
|
access: 'AKIAJAJN2G22O42XJODQ',
|
|
|
|
secret: 'Qqm8GL9vbSwrEFkQHgYouc0Ta5k0lD/xe3Xaf65Y',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-04-05 05:21:56 +00:00
|
|
|
// App
|
|
|
|
|
|
|
|
/* Homepage */
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
res.render('index', {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-04-06 19:44:51 +00:00
|
|
|
app.post('/text', function(req, res) {
|
|
|
|
if (true) {
|
|
|
|
sendText(req.body.number, req.body.msg, function(err) {
|
|
|
|
if (err)
|
|
|
|
res.send({success:false});
|
|
|
|
else
|
|
|
|
res.send({success:true});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function sendText(phone, msg, cb) {
|
2012-04-05 07:30:47 +00:00
|
|
|
var transport = nodemailer.createTransport("SES", {
|
|
|
|
AWSAccessKeyID: config.aws.access,
|
2012-04-06 19:44:51 +00:00
|
|
|
AWSSecretKey: config.aws.secret,
|
2012-04-05 07:30:47 +00:00
|
|
|
});
|
2012-04-05 05:21:56 +00:00
|
|
|
|
2012-04-05 07:30:47 +00:00
|
|
|
var mailOptions = {
|
|
|
|
transport: transport, // transport method to use
|
2012-04-06 19:44:51 +00:00
|
|
|
from: "txt@textbelt.com", // sender address
|
2012-04-05 07:30:47 +00:00
|
|
|
to: '9147727429@vtext.com',
|
|
|
|
subject: '', // Subject line
|
2012-04-06 19:44:51 +00:00
|
|
|
text: msg,
|
2012-04-05 05:21:56 +00:00
|
|
|
}
|
2012-04-05 07:30:47 +00:00
|
|
|
|
|
|
|
nodemailer.sendMail(mailOptions, function(error){
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
2012-04-06 19:44:51 +00:00
|
|
|
cb(true);
|
2012-04-05 07:30:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("Message sent!");
|
2012-04-06 19:44:51 +00:00
|
|
|
cb(false);
|
2012-04-05 07:30:47 +00:00
|
|
|
}
|
|
|
|
transport.close(function(){}); // shut down the connection pool
|
|
|
|
});
|
2012-04-06 19:44:51 +00:00
|
|
|
}
|
2012-04-05 05:21:56 +00:00
|
|
|
|
|
|
|
var port = process.env.PORT || 8080;
|
|
|
|
app.listen(port, function() {
|
|
|
|
console.log('Listening on', port);
|
|
|
|
});
|