I’ve followed a tutorial online, my goal was to make a form so users can send me an email directly from the web app and it works but only from my machine when I hit run on function in visual studio code. What should I do to make it works when I deploy it? Should I change something in package.json or maybe deploy that code separately and fetch from there? Or call it in some useEffect? Here is the code so you can get a picture.
const express = require("express");
const router = express.Router();
const cors = require("cors");
const nodemailer = require("nodemailer");
const app = express();
app.use(cors());
app.use(express.json());
app.use("/", router);
app.listen(5000, () => console.log("Server Running"));
const contactEmail = nodemailer.createTransport({
service: 'gmail',
auth: {
user: "[email protected]",
pass: "mypassword",
},
secureConnection: 'false',
tls: {
ciphers: 'SSLv3',
rejectUnauthorized: false
}
});
contactEmail.verify((error) => {
if (error) {
console.log(error);
} else {
console.log("Ready to Send");
}
});
router.post("/contact", (req, res) => {
const name = req.body.name;
const email = req.body.email;
const message = req.body.message;
const mail = {
from: name,
to: "[email protected]",
subject: "Contact Form Submission",
html: `<p>Name: ${name}</p>
<p>Email: ${email}</p>
<p>Message: ${message}</p>`,
};
contactEmail.sendMail(mail, (error) => {
if (error) {
res.json({ status: "Something went wrong, please try again." });
} else {
res.json({ status: "Message sent!" });
}
});
});