'Power Apps - Send Email To the List of Users from Collection Using Flow

I have a collection called as requiredCol_1 like this,

Name      ID      ToAddress                                                        Status
Abc       123     [email protected],[email protected],[email protected]        A        
Def       234     [email protected],[email protected]                                A
Ghi       567     [email protected],[email protected]                              A

I am looking to send email to each user and each User should receive only one email.

To do that,

I have created a requiredCol_2 as another collection

ToAddressUnique
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

I have managed to narrow down my problem now. Every User in the above collection (requiredCol_2) will receive an email. And my email body will have the Name and ID concatenated and in the form of list relevant to that particular email id.

For Example an email sent to [email protected] will look like,

To :- [email protected]

Subject :- Please Look at

Body:-

Click here and Kindly review the following,

  1. Abc - 123
  2. Def - 234
  3. Ghi - 567

Click here is a hyperlink, which I want to pass through a variable.

I am new to Powerapps and flow. So, please explain me the steps to get this to work.

This is my code so far in Power Apps - Send Email Button

//Create a Collection
ClearCollect(requiredCol_1 , Filter(Table1, User().Email in Lower(Allocators), Status = "A"));

//Unique List of Approvers
ClearCollect(requiredCol_2,Distinct(
    Split(
        Concat(requiredCol_1 , ToAddress, ","),
        ","),
    Result));
//Hyperlink Creation
set (hyperlinkvalue, "WWW.Google.Com");


Solution 1:[1]

If you want to send an e-mail, you can use one of the connectors such as Outlook.com or Office 365 (among others). And if you want the e-mail to have hyperlinks, then you will need to send a HTML e-mail, and you'll need to compose the HTML in your app. For example, the code snippet below shows using the Outlook.com connector to send the e-mail (the syntax for Office 365 will be either the same or really similar):

//Create a Collection
ClearCollect(
    requiredCol_1,
    Filter(Table1, User().Email in Lower(Allocators), Status = "A"));

//Unique List of Approvers
ClearCollect(requiredCol_2,Distinct(
    Split(
        Concat(requiredCol_1 , ToAddress, ","),
        ","),
    Result));

//Hyperlink Creation
Set(hyperlinkvalue, "WWW.Google.Com");

// E-mail body
Set(
    mailBody,
    Concatenate(
        "<p><a href=""",
        hyperlinkvalue,
        """>Click here</a> and kindly review the following:</p>",
        "<ol>",
        Concat(
            requiredCol_1,
            "<li>" & Name & " - " & ID & "</li>"
        ),
        "</ol>"
        ));

// Send e-mail
'Outlook.com'.SendEmail(
    Concat(requiredCol_2, Result, ","),
    "Please look at",
    mailBody,
    {
        IsHtml: true
    })

If you want, to send in the e-mail only the items which had that e-mail, then you'll need to filter the original table when creating each individual e-mail, like in the example below:

Set(hyperlinkValue, "www.google.com");
ClearCollect(
    distinctUsers,
    Distinct(Split(Concat(requiredCol_1, ToAddress, ","), ","), Result));
ClearCollect(
    distinctUsersWithEmail,
    AddColumns(
        distinctUsers,
        "mailBodyForUser",
        Concatenate(
            "<p><a href=""",
            hyperlinkValue,
            """>Click here</a> and kindly review the following:</p>",
            "<ol>",
            Concat(
                Filter(requiredCol_1, Result in ToAddress),
                "<li>" & Name & " - " & ID & "</li>"
            ),
            "</ol>"
        )));
ForAll(
    distinctUsersWithEmail,
    'Outlook.com'.SendEmail(
        Result,
        "Please look at",
        mailBodyForUser,
        {
            IsHtml: true
        }))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1