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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to implement a loo...
Power Automate
Unanswered

How to implement a loop to send an email from multiple senders

(0) ShareShare
ReportReport
Posted on by 9

Hi guys,How to implement a loop to send an email from multiple senders. ( Power Automate Desktop)

There are 10 email senders. there are 300 recipients. 1 sender sends email to first 10 recipients. second sender sends email to next 10 recipients and so on

 

Screenshot_167.jpg

 
 
 
 
 
 
 
 
 
 
 
 
I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    So, first, I would solid list of from and to.  You said 1st sender is 1-10, 2nd sender is 11-20, but said there is only 10 senders and 300 recipients, so the math isn’t adding up. 

     

    regardless, I would restructure your excel file for column A is from, column B is to. 

    the file should have the whole list:

    Sender 1 to recipient 1

    sender 1 to recipient 2

    sender 2 to recipient 3

    etc

     

    if it’s not already this way, I’m sure you can figure out how to make it this way in Excel. If it’s every X# of recepients like you said, sender -1 has the first 10, sender 2 has the next 10, then we can do that pretty easily. What PAD probably won’t do is use colors to differentiate different numbers of recipients. So, if send 1 has 1-9, and 2 has 10-12, we need the sender (col A), and recipient (Col b) to get this to work. I am going to assume that the numbers can change, and we will use the sender (col A), and recipient (Col b) method because this will work for both scenarios. 

     

    Now, each row is a record. 

    launch excel

    Get first free row

    create list %Recipients%

    Set variable %SendEmail% to 0 ‘this will be a boolean, 0=False and 1=True.  If true, we will send the email.

    Loop 2 to %FirstFreeRow - 1%
        read from Excel A & %Loopindex% to %Sender%
        Read from Excel B & %LoopIndex% to %Recipient%
        Add %Recipient% to list %Recipients%

        Read from Excel A & %LoopIndex% to %NextSender%
        If %Sender% = %NextSender%

            Next (Loop)

        Else ‘Sender does not equal NextSender    
            Send Email where from is %Sender% and to is %Recipients% (the list)

            Clear list %Recipients% ‘clear the list for the next sender

        End(IF)

    End(loop)

     

    good luck

             

     

     

  • AntonSokolov19 Profile Picture
    9 on at

    Hi, 

    Thanks for taking the time to respond

     

    "the file should have the whole list:

    Sender 1 to recipient 1

    sender 1 to recipient 2

    sender 2 to recipient 3

    etc"

     

    Answer, the Excel list can be rebuilt, but it is difficult. you can two separate excel files - the first is the senders and the list inside and the second is the recipients list inside

     

    " What PAD probably won’t do is use colors to differentiate"

     

    I highlighted the color to make you understand the idea/task. color is not a necessary parameter

     

    Now I'm trying to apply your code to my problem and refine it.

     

    "You said 1st sender is 1-10, 2nd sender is 11-20, but said there is only 10 senders and 300 recipients, so the math isn’t adding up. "

     

    There should be a limit on the number of emails sent from one sender - no more than 10 emails to recipients. I don't know how to do it yet. The list of senders can change. the list of recipients can change.

  • VJR Profile Picture
    7,635 on at

    Below is a Pseudo code you would want to use.

    Feel free to make amendments wherever applicable.

     

    Post back if you have any questions.

     

     

    Paste the below code into a new blank Flow editor. 

    Step through it one action at a time so that it does not go into infinite loop.

     

     

    SET SenderCounter TO 2
    SET RecipientCounter TO 1
    SET RowCounter TO 2
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\test\\Loop emails.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.GetFirstFreeRowOnColumn Instance: ExcelInstance Column: $'''A''' FirstFreeRowOnColumn=> FirstFreeRowOnSenderColumn
    Excel.GetFirstFreeRowOnColumn Instance: ExcelInstance Column: $'''H''' FirstFreeRowOnColumn=> FirstFreeRowOnRecipientColumn
    LOOP WHILE (SenderCounter) <= (FirstFreeRowOnSenderColumn - 1)
     Excel.ReadFromExcel.ReadCell Instance: ExcelInstance StartColumn: $'''A''' StartRow: SenderCounter ReadAsText: False CellValue=> SenderEmailID
     LOOP LoopIndex FROM RecipientCounter TO 10 STEP 1
     Excel.ReadFromExcel.ReadCell Instance: ExcelInstance StartColumn: $'''H''' StartRow: RowCounter ReadAsText: False CellValue=> RecipientEmailID
     SET FinalRecipientEmailID TO $'''%FinalRecipientEmailID%%RecipientEmailID%;'''
     Variables.IncreaseVariable Value: RowCounter IncrementValue: 1 IncreasedValue=> RowCounter
     END
     /# SEND EMAIL HERE using %FinalRecipientEmailID% as the list of recipients
    and use %SenderEmailID% as the sender#/
     SET FinalRecipientEmailID TO $'''%''%'''
     Variables.IncreaseVariable Value: SenderCounter IncrementValue: 1 IncreasedValue=> SenderCounter
    END
    

     

     

  • AntonSokolov19 Profile Picture
    9 on at

    Sorry I corrected my post. I work at Power Automate Desktop. I need to implement a task in this program.

     

     

     

     

  • AntonSokolov19 Profile Picture
    9 on at

    At the moment the code is 

     

    Screenshot_168.jpg

     
     
     
     
     
  • AntonSokolov19 Profile Picture
    9 on at

    Using a macro in VB, I copy each line 10 times so that one address sends 10 emails 

     

    Screenshot_98.jpg

     

    Sub insertrows()
    'Updateby Extendoffice
    Dim I As Long
    Dim xCount As Integer
    LableNumber:
    xCount = Application.InputBox("Number of Rows", "Kutools for Excel", , , , , , 1)
    If xCount < 1 Then
    MsgBox "the entered number of rows is error ,please enter again", vbInformation, "Kutools for Excel"
    GoTo LableNumber
    End If
    For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 2 Step -1
    Rows(I).Copy
    Rows(I).Resize(xCount).Insert
    Next
    Application.CutCopyMode = False
    End Sub

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard