December 18, 2024

Today, look at a widespread mistake people make while developing their Flows. The question that I see in the forums is always something like this. “My Flow is sending multiple emails when I want only one. How to send only one email?”

This isn’t a problem with Power Automate per se but with the strategy used, so today, let’s understand the problem and how to fix it. Once you know the problem, I’m sure the solution will make sense before I explain it, so let’s do it.

The problem.

Let’s look at an example to understand the issue better. Let’s say we have a Flow that sends an approval Flow to multiple people and gets the responses. After we get the responses, we want to send the result of the approval and all comments to the person that asked for it. You start building the Flow with the approval action and then add a “Send email” action.

Then you start adding the email and the Flow changes to an “Apply to each” action , and you continue writing the email.

Looks good, you test it with your email as an approver, and all looks good. After this, you add the multiple people that need to approve and start getting complaints from people who get various emails (one per approver). The issue is that Flow will run the “Send email” action per reply, which will send per approver. If you have only one, it will send only one email, but if you have multiple, it will send multiple emails.

The issue is always that people put the “Send email” action inside the “Apply to each” action, and Power Automate will do precisely what we ask. Send one email per run of the “Apply to each” action.

The solution is easy, but I hope you understand the issues. If you’re getting multiple emails, always check the action of sending them and if it’s inside a loop. If it is, then you need to pull it from inside the “Apply to each” action to the outside.

Let’s see how to do that.

The solution

The solution, as mentioned before, is simple. We need to get the “Send email” action outside the “Apply to each” action. Let’s see how to fix the problem above by removing the “Apply to each” action and using another action that can build a lovely table with the results. It’s called the “Create HTML table” action, and it looks like this.

This action will get an array and build a table with our defined results. Notice that the left part of the columns where you can see “Name”, “Response” and “Comment” was defined by us, so you can put any text that makes sense to you. After this, you can use the same “Send email” action as follows:

Now you can have an email with all the answers (regardless of how many) in the same email.

The “Approval” action has elements that contain some of the information like the “Outcome” or the “Response summary,” but they won’t provide you with a detailed view like above. If you want only the final result, these may be enough, so explore them to see if they fit your needs.

Final thoughts

The issue is not on Power Automate but how we use it. Since Power Automate does some changes for us, like adding “Apply to each” action when needed (it’s a fantastic feature, don’t get me wrong), we may not notice this change and result in issues like these.

If something happens multiple times, chances are excellent that they are within an “Apply to each” action, so check your Flows and see if one was added without noticing it.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and check out other Power Automate-related articles here.

Photo by Hiroshi Kimura on Unsplash

 

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

4 thoughts on “Power Automate: How to send only one email?

  1. Thank you for this informative article. I have a similar issue, but there are several differences. I have a process that sends an email to multiple individuals listed in a Sharepoint table. In each individuals record, are fields with data specific to the individual. For example, a link to a survey. Because the number of records involved is dynamic, and may be large. I use an Array to capture all records in the table. I use the array to capture all records. Once all records have bene captured, I want to use Power Automate to send the emails with associated links/data specific to individual. I tried to use “For Each Item” loop based on the array, but multiple Emails are going out (I assume because there are multiple Fields in each array.)

    Do you have any suggestions how to address this situation?

  2. HI there! Thanks so much for this insightful article. I was optimistic that this would finally solve my duplicate emails issue, but unfortunately I ran into another problem. After moving my “Send Email” action outside of the “Apply to Each” action, I got this error message:

    Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The inputs of template action ‘Send_an_email_(V2)_2’ at line ‘1 and column ‘4699’ is invalid. Action ‘Apply_to_each’ must be a parent ‘foreach’ scope of action ‘Send_an_email_(V2)_2’ to be referenced by ‘repeatItems’ or ‘items’ functions.’.’.

    It seems the system wants me to keep the email action within the last “apply to each” (my flow has several – one for each of the multi-choice questions in the Form that triggers the flow). Any thoughts? Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon