How to send response after sendinblue email?

366 Views Asked by At

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!

1

There are 1 best solutions below

0
On

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("/");
}});

});