docodern
docodern

Reputation: 3

How to send response after sendinblue email?

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

Answers (1)

Aayush Agrawal
Aayush Agrawal

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

Related Questions