Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

promise.all to send emails

const users = [
  {
    "name": "User 1",
    "email": "user1@gmail.com"
  },
  {
    "name": "user 2",
    "email": "user2@gmail.com"
  }
];


const sendEmailToUser = async (user) => {
   const data = {
      from: 'example@from.com',
      to: 'example@reciever.com',
      subject: 'Sample subject',
      html: 'await email()'
   };
   await mailgun.messages().send(data);              
};

(async () => {
    const sendEmailPromises = [];

    for(const user of users) {
        // Start sending all emails
        sendEmailPromises.push(sendEmailToUser(user));
    }

    // Wait for all emails to be sent
    await Promise.all(sendEmailPromises);

    // Do something
})()
Comment

PREVIOUS NEXT
Code Example
Javascript :: {"javascript error: Invalid or unexpected token c# selenium 
Javascript :: filtrer un tableau javascript 
Javascript :: javascript browse folder path-limit 
Javascript :: Javacript code that delays, based on Milliseconds 
Javascript :: Discord.js v12 member voiceChannel 
Javascript :: alpinejs checknox selectAll 
Javascript :: Javascript one parameter fat arrow 
Javascript :: amcharts 3d column chart export 
Javascript :: react Update a label when rate moves 
Javascript :: void 0 js 
Javascript :: Format Mathjax 
Javascript :: lodash uniqBy alterantive in js 
Javascript :: js function to print words on number 
Javascript :: javascript to prevent method POST from realoading 
Javascript :: how to rmeove white space in a string with jquery 
Javascript :: rails + vue js projcet demo 
Javascript :: Failed: Template parse errors: There is no directive with "exportAs" set to "ngModel" karma 
Javascript :: ternary operator return date greeting 
Javascript :: node js euro sign 
Javascript :: regex not before 
Javascript :: get random id javascript 
Javascript :: Script test to be oneOf 
Javascript :: https - node load testing- 
Javascript :: discord js mention author 
Javascript :: ngreadonly 
Javascript :: javascript return strung 
Javascript :: react native bottom sheet example 
Javascript :: js get each pair of values from an array 
Javascript :: vuejs bus.emit 2 times 
Javascript :: detect paste in textarea 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =