forked from Avdhesh-Varshney/WebMasterLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (45 loc) · 1.41 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
const express = require('express')
const app = express()
const bodyParser = require('body-parser');
const path = require("path");
const port = 5500
const nodemailer = require("nodemailer");
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname , 'public/mail.html'));
})
app.post('/', function(req, res) {
const transporter = nodemailer.createTransport({
service: "Gmail",
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: "[email protected]",
pass: "pwrxkjklvbddvsqa",
},
});
const mailOptions = {
from: "[email protected]",
to: req.body.emailid ,
subject: "Feedback form response",
text: "Thankyou"+req.body.name+" for your feedback. We will get back to you soon. Chechout Git hub repo :- https://github.com/dhairyagothi/50_days_50_web_project Regards Dhairya +919424065768 [email protected]",
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
alert("Email not sent: ", info.response);
console.error("Error sending email: ", error);
} else {
alert("Email sent: ", info.response);
console.log("Email sent: ", info.response);
}
});
req.body.button.addEventListener("click", function () {
alert("Email sent: ", info.response);
console.log("Email sent: ", info.response);
}
);
});