Home > OS >  I am trying to put in const data = to the ${body.email}. To be simple, it's for sending e-mail
I am trying to put in const data = to the ${body.email}. To be simple, it's for sending e-mail

Time:09-17

const mail = require('@sendgrid/mail');  

mail.setApiKey(process.env.SENDGRID_API_KEY);

export default async (req, res) => {
  const body = JSON.parse(req.body);

  const message = `
    Name : ${body.name}\r\n
    Prenom : ${body.prenom}\r\n
    Adresse : ${body.adresse}\r\n
    Téléphone : ${body.telephone}\r\n
    email : ${body.email} \r\n
    Type de bien : ${body.message}\r\n
    Année de construction : ${body.annee}

  `;

 const data = {
    to: ?????? 
    from: '[email protected]',
    subject: 'Nouveau Lead!',
    text: message,
    html: message.replace(/\r\n/g, '<br>')

  };



  mail.send(data);

  res.status(200).json({ status: 'Ok' });

Plz help, I am trying to put in const data = to the ${body.email}. To be simple, it's for sending e-mail while just typing in the front.

Thank you.

CodePudding user response:

Twilio SendGrid developer evangelist here.

You can set the to property on the data object to body.email like so:

 const data = {
    to: body.email,
    from: '[email protected]',
    subject: 'Nouveau Lead!',
    text: message,
    html: message.replace(/\r\n/g, '<br>')
  };
  • Related