made email from work

This commit is contained in:
Dobie Wollert
2014-10-26 02:29:04 -07:00
parent a2c5abf7ea
commit 92201a4a30
8 changed files with 118 additions and 54 deletions

View File

@ -7,6 +7,7 @@
"body-parser": "~1.9.0",
"method-override": "~2.2.0",
"mongoose": "~3.8.17",
"express-restify-mongoose": "~0.6.10"
"express-restify-mongoose": "~0.6.10",
"emailjs": "~0.3.12"
}
}

View File

@ -3,20 +3,28 @@ var express = require('express');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var mongoose = require('mongoose');
var email = require('emailjs');
var Schema = mongoose.Schema;
var restify = require('express-restify-mongoose');
mongoose.connect('mongodb://localhost/biomed');
mongoose.connect('mongodb://localhost/biomed_prod');
var emailServer = email.server.connect({
user: 'api@atlanticbiomedical.com',
password: 'success4',
host: 'smtp.gmail.com',
ssl: true
});
var Post = new Schema({
title: { type: String },
preview: { type: String },
details: { type: String },
image: { type: String },
gallery: [
{ type: String }
],
status: { type: String }
title: { type: String },
preview: { type: String },
details: { type: String },
image: { type: String },
gallery: [
{ type: String }
],
status: { type: String }
});
var PostModel = mongoose.model('Post', Post);
@ -24,12 +32,33 @@ var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride());
app.post('/api/email', function(req, res) {
if (req.body.name && req.body.email && req.body.message) {
emailServer.send({
from: 'Website <api@atlanticbiomedical.com>',
to: 'akirayasha@gmail.com',
"reply-to": req.body.email,
subject: 'Message from website',
text: 'Name: ' + req.body.name + "\n" + "E-Mail: " + req.body.email + "\n\n" + req.body.message
}, function(err, message) {
if (err) {
console.log("Failed to send message from website.", err);
}
});
res.json(null);
}
});
restify.serve(app, PostModel, {
prereq: function(req) {
return req.method === 'GET';
}
prereq: function(req) {
return req.method === 'GET';
}
});
http.createServer(app).listen(3000, function() {
console.log('Express server listening on port 3000');
console.log('Express server listening on port 3000');
});