-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
57 lines (49 loc) · 1.47 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
50
51
52
53
54
55
56
57
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.render('index');
});
app.get('/contact', function(req, res){
res.render('contact');
});
app.post('/contact/send', function(req, res){
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true, // use SSL
auth: {
user: '[email protected]',//enter email you want to send mail from,
pass: 'qddvvqqirwegpjsu'//enter passsword
},
tls:{
rejectUnauthorized: false,
}
});
var mailOptions = {
from: '"Nodemailer Bot" <[email protected]>',
to: req.body.email,
subject: 'Message from Nodemailer',
text: 'New Mail! Name: '+req.body.name+'Email: '+req.body.email+ 'Message: '+req.body.message,
html: '<p>New Mail!</p><ul><li>'+req.body.message+'</li></ul>'
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
res.redirect('/');
} else {
console.log('Message Sent: '+info.response);
res.redirect('/');
}
});
});
port = 3000;
app.listen(port);
console.log('Server is running on'+port);