Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
Node.js - SendGrid : Doesn't send to my array recipients (only in production mode)

My env :

"next": "^12.0.8",
"@sendgrid/mail": "^7.6.1"

My code - API:

import sendgrid from '@sendgrid/mail';

sendgrid.setApiKey(process.env.SENDGRID_API_KEY);

export default async function sendEmailDestinataire(req, res) {
  const msg = {
    to: req.body.email,
    from: {
      email: 'contact@aaaaaaa.fr',
      name: 'From my name',
    },
    templateId: 'd-xxxxxxxxxxxxxxxxx',
    dynamic_template_data: {
      name: req.body.name,
      email: req.body.email,
      message: req.body.message,
      file: req.body.file,
    },
  };
  console.log('====================================');
  console.log('api msg', msg.to);
  console.log('====================================');
  try {
    await sendgrid.sendMultiple(msg);
    res.json({ message: `Email has been sent` });
  } catch (error) {
    res.status(500).json({ error: 'Error sending email' });
  }
}

My code - FRONT

let listEmails = '';
if (getUserMail.edges && getUserMail?.edges[0]?.node?.email === email) {
  const tmpListEmails = getUserMail.edges[0]?.node?.listeEmails?.emails;
  listEmails = tmpListEmails.replace(' ', '').split(',');
}

const res2 = await fetch('/api/sendgridDestinataire', {
  body: JSON.stringify({
    email: listEmails.length > 0 ? listEmails : email,
    name: name,
    file: allUrls,
    message: message,
  }),
  headers: {
    'Content-Type': 'application/json',
  },
  method: 'POST',
});
await res.json();

My problem :

In my development environment everything works fine. But when I'm in production, the email is sent to the email state. And no, to those from my array. The email variable transmitted to the API sends me back the object...

Thank you in advance for your help.

And sorry for my English

Bruce

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Hello Juan Pablo, did you manage to solve it? I have the same problem

over 2 years ago · Mariana Agudelo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda