-
Notifications
You must be signed in to change notification settings - Fork 36
/
server.js
48 lines (39 loc) · 1.04 KB
/
server.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
const express = require("express");
const res = require("express/lib/response");
const app = express();
const nodemailer = require("nodemailer");
const PORT = process.env.PORT || 5500;
//Middleware
app.use(express.static("public"));
app.use(express.json());
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/contactform.html");
});
app.post("/", (req, res) => {
console.log(req.body);
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: "8565887271",
},
});
const mailOptions = {
from: req.body.email,
to: "[email protected]",
subject: `Message from ${req.body.email}: ${req.body.subject}`,
text: req.body.message,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.send("error");
} else {
console.log("Email sent: " + info.response);
res.send("success");
}
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});