Reputation: 3
Hollo! I have this code to send email for me from contact form
app.post("/contact", (req, res)=>{
......
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
console.error(error);
});
res.redirect("/");
});
How I can response success page if email is send or error page if there is some error? Is it posible? Thx!
Upvotes: 0
Views: 383
Reputation: 81
You can do this by applying a check in your callback like this
app.post("/contact", (req, res)=>{
......
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
if(error) {
res.redirect("/errorPage");
} else {
res.redirect("/");
}});
});
Upvotes: 1