web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Loop around a collecti...
Power Apps
Unanswered

Loop around a collection of email addresses and use Office365.SendMail to send an email to each email address in the collection

(0) ShareShare
ReportReport
Posted on by 1,302

Hi

 

I have a collection of email address and I want to send out an email to each email address in the collection with a time delay of 30 seconds between each email being sent.

 

I can see how to get the 30 seconds delay using a timer, but I am struggling to send out an email to each email address in the collection.

 

I tried using ForAll(emailCollection,.......

but i cannot use Set() or UpdateContext() inside a ForAll construct.

 

So using pseudo code :-

Loop around all email addresses

send email 

wait 30 seconds

end loop

 

I could use Components to send the email and wait 30 seconds, but i still need to give the component each email address in the collection.

 

Anybody any ideas ?

 

Thanks

 

Nigel

Categories:
  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    Hi @NigelP ,
    I would firstly get a collection with some numbers

    Clear(colEmailSend);
    ForAll(
     emailCollection, 
     Collect(
     colEmailSend,
     Last(
     FirstN(
     AddColumns(
     emailCollection,
     "IDNo",
     CountRows(
     colEmailSend
     )+1
     ), 
     CountRows(colEmailSend)+1
     )
     ) 
     )
    );

    Note that the below comes from this post from the Dynamic People, so I have not tested it, but it looks like it will do the job for you.
    Do a CountRows(colEmailSend) to get the number of mails to send

    UpdateContext({vEndLoop: ​CountRows(colEmailSend)})

    Add a button to trigger the flow with OnSelect

    UpdateContext({vRunNos: 0});
    UpdateContext({vTimerStart: true})​

    Add a Timer control and set Timer.Duration to 30000 (30 seconds) - with Timer.Start

    vTimerStart

    and Timer.Repeat to

    If(vRunNos >= vEndLoop – 1, false, true)​

    and Timer.OnTimerEnd to

    Office365Outlook.SendEmailV2(
     Lookup(colEmailSend,
     IDNo = vRunNos,
     EmailAddressFieldName
     ),
     TitleStuff,
     BodyStuff
    );
    UpdateContext({vRunNos: vRunNos + 1});
    If(vRunNos >= vEndLoop – 1, UpdateContext({vStartTimer: false}))

    I will leave you to tidy up any code as I free-typed it

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • NPrice99 Profile Picture
    1,302 on at

    Thanks @WarrenBelz - very useful.  In your example can I tell if a Office365.SendMail has failed ?

    eg Set(boolFailed,Office365.SendMAil(colEmailSend..... )

  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    Hi @NigelP ,

    As you are not using a Flow to do the email, you cannot return a value in the same way as setting a variable to the Flow return.

    If you are asking about a debugging exercise, look in your Sent Items in Outlook.

    You may also consider doing a IsMatch(YourEmailAddress,Email) ForAll to see if they are all valid. If they are and the code works, it should always work.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard