cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Basic_User007
Kudo Kingpin
Kudo Kingpin

Send one email to list of multiple email addresses

I am working with a SharePoint list which contains multiple lines of data. Within the data is email addresses where the same person can be included more than once.

 

What I want to do is send an email to the email recipients but if the email recipient is listed more than once it should only send one email. 

 

I am starting with 'manual trigger' to start the flow - 'get items' referring to my SharePoint list - when I add 'send an email' it send the email per each item on the list so the one email address can receive 100's of emails.

 

How do I change the flow so it is only sending one email to each recipient?  

2 ACCEPTED SOLUTIONS

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @Basic_User007,

 

I think this would be possible if you use a union function to get the distinct values.

 

Below is an example how you could achieve this.

 

1. Add an initialize variable of type array

emailaddressarray.png

2. Append the email address values to that array. In my example I am using value output from a Get Items action.

 

I am using a SharePoint list column is called PeopleTest (type Person or Group) and I am using the Email field of an item.

appendemailaddresses.png

3. Add an compose action with the following expression. This is the union to get the distinct values.

union(variables('UniqueEmailAddressesArray'), variables('UniqueEmailAddressesArray'))

unioncompose.png

4. Add a parse json action to parse the output

{
    "type": "array",
    "items": {
        "type": "string"
    }
}

parsejsonarray.png

5. Use an send an email action inside of an apply to each loop to send the individual emails

sendemail.png

View solution in original post

Expiscornovus
Super User
Super User

Hi @Basic_User007,

 

In my example I was using a person column which allows multiple selections, which gives back an array as the result. How is your column in the list setup? Are you able to change that to allow multiple selections?

 

 

allowmultipleselections_column.png

View solution in original post

6 REPLIES 6
Expiscornovus
Super User
Super User

Hi @Basic_User007,

 

I think this would be possible if you use a union function to get the distinct values.

 

Below is an example how you could achieve this.

 

1. Add an initialize variable of type array

emailaddressarray.png

2. Append the email address values to that array. In my example I am using value output from a Get Items action.

 

I am using a SharePoint list column is called PeopleTest (type Person or Group) and I am using the Email field of an item.

appendemailaddresses.png

3. Add an compose action with the following expression. This is the union to get the distinct values.

union(variables('UniqueEmailAddressesArray'), variables('UniqueEmailAddressesArray'))

unioncompose.png

4. Add a parse json action to parse the output

{
    "type": "array",
    "items": {
        "type": "string"
    }
}

parsejsonarray.png

5. Use an send an email action inside of an apply to each loop to send the individual emails

sendemail.png

View solution in original post

My flow is erroring at the first apply to each branch with the following error message...

 

The execution of template action 'Apply_to_each_3' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each')?['AssignedTo2']' is of type 'Object'. The result must be a valid array.

Are you able to post a full screenshot of all your flow steps @Expiscornovus I'm trying to work out what is causing the error. 

@Expiscornovus can you spot the error? 

 

Basic_User007_0-1610460848840.png

 

Expiscornovus
Super User
Super User

Hi @Basic_User007,

 

In my example I was using a person column which allows multiple selections, which gives back an array as the result. How is your column in the list setup? Are you able to change that to allow multiple selections?

 

 

allowmultipleselections_column.png

View solution in original post

In your screenshot it looks like you are using a double apply to each from value - people test & as per my screenshot below. Once I removed this I got it all working perfectly. 

 

I have been able to use the same steps & formula to compose month field in email too. 

 

Thank you so much for helping me out on this. Can see these steps will be useful in a lot of other flows to come 🙂 Thanks again!!! ***** 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,881)