Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

0

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

over 2 years ago · Mariana Agudelo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!