-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (42 loc) · 1.09 KB
/
app.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
"use strict";
var express = require('express'),
path = require('path'),
http = require('http'),
nodemailer = require("nodemailer");
var app = express(),
port = process.env.VMC_APP_PORT || 3001,
host = process.env.VCAP_APP_HOST || 'localhost';
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "{{[email protected]}}",
pass: "{{pass}}"
}
});
app.configure(function () {
app.set('port', port);
app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' */
app.use(express.bodyParser()),
app.use(express.static(path.join(__dirname, 'public')));
});
app.post('/signup', function(req, res) {
var data = req.body;
if(data && data.email){
// send mail with defined transport object
smtpTransport.sendMail({
from: "{{[email protected]}}",
to: "{{[email protected]}}",
subject: "Mikapp: " + data.email + " subscribed",
text: data.email + " subscribed"
}, function(error, response){
if(error){
res.send(500, error);
} else {
res.send({
status: "success"
});
}
});
}
});
app.listen(port, host);