-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (45 loc) · 1.44 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
const path = require('path');
const express = require('express');
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
const port = process.env.PORT || 8080;
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + '/public'));
app.get('*', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
/*app.get('/resume', function(req, res){
//var path=require('path');
// var path = path.resolve(".")+'/uploads/'+file;
res.download('./public/resume.pdf'); // magic of download fuction
});*/
app.post('/contactus', function (req, res) {
var transporter = nodemailer.createTransport({
service: 'Yandex',
auth: {
user: process.env.EMAIL, // Your email id
pass: process.env.PASSWORD // Your password
}
});
var mailOptions = {
from: process.env.EMAIL, // sender address
to: 'enikolaenko330@gmail.com', // list of receivers
subject: 'Contact through website', // Subject line
text: `Name: ${req.body.name}
Email: ${req.body.email}
Message: ${req.body.message}`
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
res.json({status: 500});
return console.log(error);
}
console.log('Message sent: ' + info.response);
res.json({status: 200});
});
});
app.listen(port, function () {
console.log('Listening on...');
});