-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
87 lines (76 loc) · 2.46 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require('express');
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
const nodemailer = require('nodemailer');
const path = require('path');
var port = process.env.PORT || 8080
const app = express();
//view engine setup
app.engine('handlebars', exphbs({
extname: "handlebars",
defaultLayout: false,
layoutsDir: "views/"
}));
app.set('view engine', 'handlebars');
//Static folder
app.use('/public', express.static(path.join(__dirname, 'public')));
// Body Parser middleware
app.use(bodyParser.urlencoded({ extended: false}));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.render('contact');
});
app.post('/send', (req,res) => {
const output =
`<h1>Thank you for using our service</h1>
<h3>Contact details</h3>
<h4>
<div>Name: ${req.body.name}</div>
<div>College: ${req.body.company}</div>
<div>Email: ${req.body.email}</div>
<div>Phone: ${req.body.phone}</div>
</h4>
<h3>Message</h3>
<div> ${req.body.message}</div>`
console.log(req.body);
var transporter = nodemailer.createTransport({
service: 'gmail',
//port: 587,
//secure: false,
auth: {
user: '[email protected]', //Set your sender email address
pass: '********', //Give your password for uuthentication
},
/*tls: {
rejectUnauthorized: false
}*/
});
var mailoption = {
from: '[email protected]', // sender address
to: req.body.email, // list of receivers
subject: "Node test", // Subject line
//text: "Hello world?", // plain text body
html: output, // html body
}
// send mail with defined transport object
transporter.sendMail(mailoption, (err) => {
if(err) {
console.log(err);
}
else {
console.log('Email Sent');
}
});
//console.log("Message sent: %s", info.messageId);
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
//console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
res.render('thankyou');
});
app.get('/views/contact.handlebars',(req,res)=>{
res.render('contact');
})
app.listen(port, () => {
console.log('server started');
});