showing results for - "promise all to send emails"
Giulio
09 May 2016
1const users = [
2  {
3    "name": "User 1",
4    "email": "user1@gmail.com"
5  },
6  {
7    "name": "user 2",
8    "email": "user2@gmail.com"
9  }
10];
11
12
13const sendEmailToUser = async (user) => {
14   const data = {
15      from: 'example@from.com',
16      to: 'example@reciever.com',
17      subject: 'Sample subject',
18      html: 'await email()'
19   };
20   await mailgun.messages().send(data);              
21};
22
23(async () => {
24    const sendEmailPromises = [];
25
26    for(const user of users) {
27        // Start sending all emails
28        sendEmailPromises.push(sendEmailToUser(user));
29    }
30
31    // Wait for all emails to be sent
32    await Promise.all(sendEmailPromises);
33
34    // Do something
35})()
36
similar questions
queries leading to this page
promise all to send emails