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, 
body = JSON.parse(event.body);
const request ="send", { version: "v3.1" }).request({
Messages: [
    From: {
      Email: process.env.MAIL_FROM_ADDRESS,
    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="">Mailjet</a>! 
 </h3><br />May the delivery force be with you!',
 console.log("sending mail");
.then((result) => {
  console.log("resultat fra mailjet: " + JSON.stringify(result.body));
. catch((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!