Today a simple template, but quite powerful if you extend it to your needs. I mentioned this example briefly in my "Create a task" action reference article, but I want to expand on the idea and the strategy that can be used. So here's how to receive an email and add it to Planner using Power Automate.
If you use a shared mailbox, use the "When a new email arrives in a shared mailbox (V2)" trigger instead of the one we use here.
Where do we save time?
We want to react to emails that arrive and automate creating tasks, assigning people, and archiving the email. This way, you'll save time by removing the following actions:
- First, read the email and check if it fits the rules to create a task.
- Then, create a new Planner task.
- Copy the values to the Planner task.
- Assign to the people in the email.
- Add tags to the task based on the rules.
- Archive the email in the folder.
It's a lot of tiny tasks that add up over time. With this template, you don't have to do any, so we can automatically receive an email and add it to Planner.
The Template
We will start with the "When a new email arrives" trigger. We'll leave it as is, but you should look at the parameters if they need to be changed to fit your rules.
We use the "Subject Filter" field to only get emails that contain a specific string in the subject. Leave it empty to get all emails, and change the other filters to fit your rules.
Get and check the emails
Now that we have a trigger, let's check the people that are in the TO field. To do it, we'll use the length function in a "Condition" action.
length(triggerOutputs()?['body/toRecipients'])
Since the toRecipients contains a string and not an email, we need to break it into an array of emails using the split function.
split(triggerOutputs()?['body/toRecipients'],';')
You can use a "Compose" action since we'll only need an array to check and add to the list of emails.
If they exist, we'll check if they exist in our organization.
We're doing a bunch of stuff here. First, we're using an "Apply to Each" action to check all values that the split function returns inside the compose action. After that, we're using a "Condition" action to check if the array doesn't contain the email. If it doesn't, we can use the "Append to Array Variable" action to get the values in the array.
There's one point that I want to explain a bit more and that's the "Get user profile" action. The action will return an error if it can't find the person in the organization. Since any mail can be inserted, we're checking if it fails and if it does ignore it. To do it, configure the "run after" setting of the next action so it also runs when the "Get user profile" action has failed. After that, we need a second "Compose" action so that, regardless of whether we have an error or not, the "Apply to Each" action will continue. Otherwise, we'll go into the right branch but since there was an error the Flow will fail regardless.
Please notice that we're using the item function to both check and add to the array. Please check the item function reference for more details on why we're doing this.
If you want to add the CC
You can extend this template to get the CC emails as well. You need to copy and paste the "Check if I have any value in the TO field" to do the same action if you want to do it. Please note that the trigger will only return the CC field when CC values are in the email. So you need to check if the cc field exists before making the comparison; otherwise, your Flow will fail.
Add the task
Now that we have everything ready, let's add the task with:
- The subject of the email as the title without changing it
- The body of the email is the description, but first, we'll convert the HTML into text using the "HTML to Text" action.
- Add the people as assigned.
We use 3 actions to add all elements to the task. The "Create a task" action can also assign people with its "Assigned User Ids" field, so you can drop the second action if you prefer. The description still needs the "Update task details" action, because the "Create a task" action has no description field.
- "Create a task" action to set the title and the bucket.
- "Update task" action to set the assigned users.
- "Update task details" action to set the description.
Getting the email is easy. We only need to use the join function with the semi-colon as the separator:
join(variables('PEOPLE_TO_CHECK'),';')
Archive the email
The last step is moving the email out of the inbox. We'll use the "Move email (V2)" action for it.
The action needs two values:
- Message Id: A message ID is the unique identifier of one email. The trigger returns it, so pick "Message Id" from the dynamic content, or use this expression:
triggerOutputs()?['body/id']
- Folder: The folder that will receive the email, for example
Archive.
Place the action after the three Planner actions. If the task can't be created, the email stays in the inbox, so you can find it and try again. If the email arrived in a shared mailbox, fill in "Original Mailbox Address" as well.
Non-intuitive behaviors
The "Get user profile" action can return a Forbidden error
If your organization blocks one of the profile fields that the "Get user profile" action asks for by default, it returns a 403 error. Open "Select fields" in the action and list only what we need, for example id,mail,displayName,userPrincipalName.
Moved emails can be skipped
The trigger looks at the date an email was received, not the date it was moved. An older email that is moved into the watched folder can be skipped. If a mailbox rule moves emails out of the Inbox, set the trigger's "Folder" to the folder where the rule puts them.
Limitations
Planner limits
A plan holds up to 9,000 tasks, and 3,000 of them can be active (not completed). A task can have up to 20 assignees. When a limit is reached, Planner returns a 403 error. Delete or archive completed tasks regularly.
Planner connector throttling
The connector allows 100 calls per connection every 60 seconds. This flow uses at least three Planner calls per email, so about 33 emails per minute is the ceiling. If your mailbox gets bursts of emails, add a "Delay" action before the Planner actions.
Basic plans only
The connector works with basic plans. Premium plans are not available through it, so use a basic plan for this flow.
Large emails
The trigger skips emails over 50 MB, or over your Exchange admin's limit if it is lower. Ask senders to share a link instead of attaching the file.
Final Thoughts
I like this template a lot because I can showcase a lot of functions and actions. Also, I like that we can receive an email and add it to Planner automatically, without having to do any time-consuming and boring tasks while saving a ton of time in the long run.
Finally, I left you a link for each, and the template is fully commented so that you can learn a bit from it.
Photo by Volodymyr Hryshchenko on Unsplash
No comments yet
Be the first to share your thoughts on this article!