const nodemailer = require("nodemailer");
router.post("/register", (req, res) => {
const { fname, lname, email, subject, msg } = req.body;
try {
let transporter = nodemailer.createTransport({
host: "smtppro.zoho.in",
port: 465,
secure: true,
auth: {
pass: "myAppPassword", // },
});
const mailOptions = {
to: email,
subject: "Website Form",
html: `
First Name : ${fname} <br>
Last Name : ${lname} <br>
Email : ${email} <br>
Subject : ${subject} <br>
Message : ${msg}
`,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log("Error", error);
res.status(401).json({ status: 401, error });
} else {
console.log("Email sent" + info.response);
res.status(201).json({ status: 201, info });
}
});
} catch (error) {
res.status(401).json({ status: 401, error });
}
});
Troubleshooting Steps Taken:
I've verified the email address and password used in the auth section of the transporter configuration match my Zoho account credentials.
Double-checked all firewall settings on the server to ensure they don't block outgoing traffic on port 465.
Tested the email sending functionality on the server using a tool like telnet and was able to connect to Zoho's SMTP server.