-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
106 lines (98 loc) · 3.66 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Initialization
const http = require('http');
const fs = require('fs');
const nodemailer = require('nodemailer');
const express = require('express');
const app = express();
const bodyparser = require('body-parser')
const index = fs.readFileSync('index.html');
// Mail sending via nodemailer package
// Rending static files
app.use(bodyparser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/images', express.static(__dirname + '/public/images'));
app.use('/contactform', express.static(__dirname + '/public/contactform'));
app.use('/lib', express.static(__dirname + '/public/lib'));
// app.use('/index', express.static(__dirname + '/public/index'));
// POST route from contact form
app.post('/contact', (req, res) => {
// Instantiate the SMTP server
const smtpTrans = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: '77Psalms77'
}
})
// Specify what the email will look like
const mailOpts = {
from: '[email protected]', // This is ignored by Gmail
to: '[email protected]',
subject: 'New message from contact form at Rauwela.com',
html: '<b>Name: </b>' + `${req.body.name}` + '<br>' +
'<b>Land Mark: </b>' + `${req.body.landmark}` + '<br>' +
'<b>Address: </b>' + `${req.body.address}` + '<br>' +
'<b>Phone: </b>' + `${req.body.phone}` + '<br>' +
'<b>Email: </b>' + `${req.body.email}` + '<br>' +
'<b>Product: </b>' + `${req.body.product}` + '<br>' +
'<b>Timing: </b>' + `${req.body.timing}` + '<br>' +
'<b>Message: </b>' + `${req.body.message}`
}
// Attempt to send the email
smtpTrans.sendMail(mailOpts, (error, response) => {
console.log('Into Mail sending block');
if (error) {
console.log('Mail is not sent Error');
// res.render('contact-failure') // Show a page indicating failure
}
else {
console.log('Mail is sent Successfully');
// res.render('contact-success') // Show a page indicating success
}
})
})
// CTA mail sending
app.post('/ctaform', (req, res) => {
// Instantiate the SMTP server
const smtpTrans = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: '77Psalms77'
}
})
// Specify what the email will look like
const mailOpts = {
from: '[email protected]', // This is ignored by Gmail
to: '[email protected]',
subject: 'New message from contact form at Rauwela.com',
html: '<b>Mail Id: </b>' + `${req.body.frommailid}` + '<br>' +
'<b>Subject: </b>' + `${req.body.subject}` + '<br>' +
'<b>Message: </b>' + `${req.body.messagetext}`
}
// Attempt to send the email
smtpTrans.sendMail(mailOpts, (error, response) => {
console.log('Into Mail sending block CTA');
if (error) {
console.log('Mail is not sent Error CTA');
// res.render('contact-failure') // Show a page indicating failure
}
else {
console.log('Mail is sent Successfully CTA');
// res.render('contact-success') // Show a page indicating success
}
})
})
app.get('/', function(req, res){
res.send(fs.readFileSync('index.html', 'utf8'));
});
// Basic node server
app.listen(process.env.PORT || 7000, function() {
console.log("LISTENING!");
});