-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (48 loc) · 1.25 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
49
50
51
52
const express = require("express");
const router = express.Router();
const cors = require("cors");
const nodemailer = require("nodemailer");
// server used to send send emails
const app = express();
app.use(cors());
app.use(express.json());
app.use("/", router);
app.listen(5000, () => console.log("Server Running"));
console.log(process.env.EMAIL_USER);
console.log(process.env.EMAIL_PASS);
const contactEmail = nodemailer.createTransport({
service: "gmail",
auth: {
user: "********@gmail.com",
pass: "",
},
});
contactEmail.verify((error) => {
if (error) {
console.log(error);
} else {
console.log("Ready to Send");
}
});
router.post("/contact", (req, res) => {
const name = req.body.firstName + req.body.lastName;
const email = req.body.email;
const message = req.body.message;
const phone = req.body.phone;
const mail = {
from: name,
to: "********@gmail.com",
subject: "Contact Form Submission - Portfolio",
html: `<p>Name: ${name}</p>
<p>Email: ${email}</p>
<p>Phone: ${phone}</p>
<p>Message: ${message}</p>`,
};
contactEmail.sendMail(mail, (error) => {
if (error) {
res.json(error);
} else {
res.json({ code: 200, status: "Message Sent" });
}
});
});