-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (42 loc) · 1.38 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var router = express.Router();
var nodemailer = require('nodemailer');
app.use(express.static(__dirname + '/static'));
app.use( bodyParser.json());
app.listen(process.env.PORT || 5000);
app.get('/[^\.]+$', function(req, res){
res.set('Content-Type', 'text/html')
.sendfile(__dirname + '/static/index.html');
});
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '',
pass: ''
}
});
router.post('/contact', function(req, res) {
var htmlTpl = '<h4>Message from' + ' ' + req.body.params.name + '</h4><p><span>' + req.body.params.email + '</span</p><p>' + req.body.params.comments + '</p>';
mailOptions = {
from: req.body.params.email,
to: '[email protected]',
subject: req.body.params.subjectList,
html: htmlTpl
};
transporter.sendMail(mailOptions, function(error, response) {
if(error) {
res.send({ success: false, message: error });
console.log(error);
} else {
res.send({ success: true, message: 'Success.' });
console.log('Mail sent Successfully!');
}
transporter.close();
});
});
router.get('/test', function(req, res) {
res.json({ message: 'hooray! welcome to our api!' });
});
app.use('/api', router);