Netlify function is working in netlify dev but not in deploy preview

I’ve created a function which send email from a form on the website through mailjet.
The function works when I use netlify dev locally but does not work from deploy preview… Don’t know what goes wrong. The problem is that request to mailjet never seeme to be run. the console.logs in the promise or catch is not outputed. When run in Netlify dev those are outputed and an email is sent

Here is the code from the function I’m calling:

exports.handler = async function(event, context) {
const mailjet = require("node-mailjet").connect(process.env.MJ_APIKEY_PUBLIC, 
process.env.MJ_APIKEY_PRIVATE);
body = JSON.parse(event.body);
console.log(body);
console.log(process.env.MAIL_FROM_ADDRESS);
console.log(process.env.MAIL_TO_ADDRESS);
const request = mailjet.post("send", { version: "v3.1" }).request({
Messages: [
  {
    From: {
      Email: process.env.MAIL_FROM_ADDRESS,
      Name: body.name.value,
    },
    To: [
      {
        Email: process.env.MAIL_TO_ADDRESS,
        Name: "from Sender",
      },
    ],
    Subject: body.title.value,
    TextPart: body.message.value,
    CustomID: "KontaktOss",
    // HTMLPart: '<h3>Dear passenger 1, welcome to <a href="https://www.mailjet.com/">Mailjet</a>! 
 </h3><br />May the delivery force be with you!',
   },
 ],
});
 console.log("sending mail");
request
.then((result) => {
  console.log("resultat fra mailjet: " + JSON.stringify(result.body));
 })
. catch((err) => {
  console.error(JSON.stringify(err));
 });
console.log("line 33");
return {
statusCode: 200,
body: JSON.stringify({ message: "Mailen er sendt" }),
};

};

Hi @SatheesA,

It’s a bit hard to say why your function is not working when deployed. First, when running locally using netlify dev, function can behave differently from when it is deployed on Netlify as the CLI uses a completely different code-base to emulate how Netlify works. That said, have you tried console.log-ing the value of request to make sure it is being run? I also noticed that you don’t have an await before the mailjet call. Can you try adding that and see if that helps?

Betting $10 on this one!