-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (59 loc) · 1.71 KB
/
app.js
File metadata and controls
71 lines (59 loc) · 1.71 KB
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
//jshint esversion:6
const express = require("express");
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static("public"));
// variables
var senderName;
var senderEmail;
var senderPhone;
var subject = "New contact from enquiry";
// Get requests
app.get("/", function(req, res){
res.render("home");
});
app.get("/contact", function(req, res){
res.render("contact");
});
app.post("/contact", function(req, res){
senderName = req.body.senderName0;
senderEmail = req.body.senderEmail0;
senderPhone = req.body.senderPhone0;
message = req.body.senderMessage0;
var body = "Name: " + senderName + "<br /> Email: " + senderEmail + "<br /> Phone no.: " + senderPhone + "<br /> Message: " + message;
var transporter = nodemailer.createTransport({
service: 'hotmail',
auth: {
user: 'node-123-123-112233-321@outlook.com',
pass: 'newPassword123'
}
});
var mailOptions = {
from: 'node-123-123-112233-321@outlook.com',
to: 'brainseednetworks931@gmail.com',
subject: subject,
text: body,
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
res.send(error);
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
res.redirect('/');
})
// Serving listening on Port
let port = process.env.PORT;
if(port == null || port == ""){
port = 3000;
}
app.listen(port , function () {
console.log("Server started Successfully");
});