Send mail to multiple contacts Ionic framework

1

I have an example of sending emails using email composer. At the moment I send emails to a user, but I would like to know how I send the same email to an array of contacts.

then I share my code:

app.js

.controller('General', function($scope){
  $scope.EnvioMail= function() {
    $scope.contactos=[{correo:"[email protected]"},{correo:"[email protected]"},{correo:"[email protected]"},{correo:"[email protected]"}];
    for(var i=0; i<$scope.contactos.length;i++){
      alert($scope.contactos[i].correo);
    }
    $scope.nombre="[email protected]";
    if(window.plugins && window.plugins.emailComposer) {
      window.plugins.emailComposer.showEmailComposerWithCallback(function(result) {
       alert("Response ->");
      }, 
      "Esta es una prueba para enviar mails desde tu aplicacion ionic", // Subject
      "",                      // Body
      [$scope.nombre],    // To EN ESTA PARTE QUIERO ENVIARLE A $scope.contactos[i].correo
      null,                    // CC
      null,                    // BCC
      false,                   // isHTML
      null,                    // Attachments
      null);                   // Attachment Data
    }
  }
})

index.html

<ion-content ng-controller='General'>
  <br><br>
  <button class="button button-assertive" ng-click="EnvioMail()">enviar mail</button>
</ion-content>

What I really want is to send this email to $scope.contactos[i].correo

    
asked by Dimoreno 26.07.2016 в 08:20
source

1 answer

0

Create an array with only the emails. You can use the map () function to do this:

$scope.listaCorreos = $scope.contactos.map(
  function(contacto){ 
    return contacto.correo;
  });

Thus, Correos list will be:

 ["[email protected]","[email protected]","[email protected]","[email protected]"]

As a general rule, the ideal would be that for data protection and privacy an email recipient did not see who else the email was sent to (unless it was between coworkers, friends, etc.).

Therefore, what I usually do is send the mail to the same account that sends it, and add in BCC (the rest of the hidden senders) the addressees addresses:

window.plugins.emailComposer.showEmailComposerWithCallback(function(result) {
           alert("Response ->");
          }, 
          "Esta es una prueba para enviar mails desde tu aplicacion ionic", // Subject
          "",                      // Body
          "[email protected]",     // O directamente $scope.listaCorreos
          null,                    // CC
          $scope.listaCorreos,     // BCC
          false,                   // isHTML
          null,                    // Attachments
          null);                   // Attachment Data
    
answered by 26.07.2016 / 12:46
source