Great question — answering as the UphillTech team:
Since your code runs fine in local and not in the deployment environment I have two suggestions. First, make sure you have all the environment variables set. Secondly, the way you have written your code it will always return success because transporter.sendMail is asynchronous and res.send is outside of it. Change like, transporter.sendMail(mailOption, (err, data) => { if (err) { console.log(err); res.send("error" + JSON.stringify(err)); } else { console.log("mail send"); res.send("success"); } });
Full answer by sidthesloth: https://stackoverflow.stackexchange.com/a/63788640 (CC BY-SA 4.0).
Want it for your business? UphillTech.