help on arrays in Google Apps Script

1

I need to send a reminder message to certain email recipients, I have the following structure

function recordatorio () {
    var asunto      = "Recordatorio de felicitación";   
    var nombrebuzon = "Comunicación Global Engineering Mexico";
    var me          = Session.getActiveUser().getEmail();
    var Mensaje = "Buen día:<br><p>Les recuerdo que el día <b>" + (day+1) + " de "+ nameMonth +"</b> será el cumpleaños de <b>" + rNames + "</b>,"+
                  " por lo que sugerimos una felicitación personal.<p>"+
                  "<br>Para reforzar esta iniciativa <b>Comunicacion Global Engineering Mexico</b> le enviará al festejado(a) una postal de cumpleaños con la firma de la dirección.<br><br>Atentamente<br>"+
                  "<b>Comunicación Global Engineering Mexico<br>Strategy & Control</b>"+     
                  "<br>";


        Logger.log("Procesando recordatorio de Felicitacion para: " + remminderMailChief);

        GmailApp.sendEmail(remminderMailChief,asunto, "", {htmlBody: Mensaje, name: nombrebuzon, from: me});
        Utilities.sleep(1000); 

}

Where: "rNames" is an arrangement or list with names separated by commas

[Carlos Alberto Ortiz , Miguel Flores García]

"remminderMailChief" is an arrangement or list of emails separated by commas

[[email protected], [email protected]]

What I want to do is send an email to [email protected] changing it in the Message rName="Carlos Alberto Ortiz" and likewise send an email to the second email [email protected] changing it in the Message rName=" Miguel Flores García "

How do I send them independently?     I mean that the email arrives at [email protected] but with the name of "Carlos Alberto Ortiz" and the second email the other name.

    
asked by Víctor Hernández 09.11.2017 в 19:03
source

1 answer

0

I leave this code that I have tried and it works perfectly.

All the details are commented on in the same code.

I hope it serves you:

function doGmail() {

     /*Calcular la cuota de mensajes disponibles*/
      var intEMailQuota = MailApp.getRemainingDailyQuota();
      var arrNombres=["Carlos Alberto Ortiz" , "Miguel Flores García"];  
      var arrEMails=["[email protected]" , "[email protected]"];

      /*Será más simple combinar los dos arrays*/
      var arrDatos = [];
      for(var n=0;n<arrNombres.length;n++){
            arrDatos.push({nombre:arrNombres[n],email:arrEMails[n]});
      }

      /*Calculamos total de emails a enviar, para verificar si tenemos cuota*/
      var intTotal=arrDatos.length;

      /*Verificamos si los mensajes a enviar no exceden la cuota*/
      if (intTotal<intEMailQuota){  
            arrDatos.forEach(function(element) {

                /*Variables para el envío*/
                var strNombre=element.nombre;
                var strEMail=element.email;
                var strAsunto='Prueba de mensaje';

                /*En este caso se toma el mensaje de un template perteneciente al mismo script*/
                var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();

                /*Lanzamos el envío*/
                MailApp.sendEmail({
                    to: strNombre + '<'+strEMail+'>',
                    subject: strAsunto,
                    htmlBody: htmlBody,
                });

           });

      } else {

            Logger.log('La cantidad de mensajes a enviar excede tu cuota diaria');            

      }  

}
    
answered by 10.11.2017 / 01:46
source