Managing a group email inbox with Power Automate by Justin
You can see this scenario explained step by step at Scenario: Managing a group email inbox.
Here we will present a solution using Microsoft Office 365's Power Automate. I use this tool extensively because it is available to me at work through the Office 365 license provided to me. For demonstration purposes here, I use a developer license. You can read more about this free license for trial use at https://docs.microsoft.com/en-us/powerapps/maker/developer-plan.
You can see the entire flow below. Further, we will go through it step by step.
So we have a group email account that we need to listen to for incoming emails. This is a trigger inside Power Automate that we can use called "When a new email arrives in a shared mailbox (V2)". We indicate the email address of this shared mailbox and the folder we will be listening to. Here we will listen to the "Inbox" folder. You can also set a filter so the automation will only run when the emails come from certain people or with certain words in the subject line. I've left these all blank since we want to process all emails. For the property "Include attachments" I have said no, since we will not be processing the attachments to emails in this automation. By not bringing in the attachments into the automation it makes it so the automations can run quicker.
Next we initialize a string variable and call it "folder" to use later. Power Automate requires us to initialize variables near the beginning of the flow.
Next we use the Compose action to take the email address of the sender and turn all capital letters to small letters. In the "Inputs" field, click "Add dynamic content". The Dynamic Content panel opens and we click on the "Expression" tab. Then input the "toLower()" function with your input inside the parentheses, which is "triggerOutputs()?['body/from']". After typing this, click the "Update" button and the Compose box will be filled with the red/pink box that says "fx toLower(...)"
Next we use the "List rows present in a table" action to look up the sender's email address in the Excel spreadsheet. Your table must be formatted as a table in Excel and then you select that table. You next do a Filter Query where the "Email" column is equal to the "From" email address (the sender's email address). We want a maximum of 1 row so we set "Top Count" to 1.
Note: The screenshot below shows how to format data as a table in Excel.
Next is our condition. We want to check that we received at least one row of data from the spreadsheet. So in our condition we use the Expression panel to make the formula: length(body('List_rows_present_in_a_table')['value'])
If the condition is met, then we check the value of the "Region" column in our spreadsheet. Microsoft assigns a long, unique identifier to our subfolders, and we want to select that long, unique identifier based on the value in our Region column. Like:
North= AAMkADNlZjgxOTlmLWJhYzQtNDhjNy1iOTBiLTBhYzRhMDA3NTMyNgAuAAA_AAA=
South= AAMkADNlZjgxOTlmLWJhYzQtNDhjNy1iOTBiLTBhYzRhMDA3NTMyNgAuAAAJmAAA=
East= AAMkADNlZjgxOTlmLWJhYzQtNDhjNy1iOTBiLTBhYzRhMDA3NTMyNgAuAAAUJoAAA=
West= AAMkADNlZjgxOTlmLWJhYzQtNDhjNy1iOTBiLTBhYzRhMDA3NTMyNgAuAAAAUJpAAA=
We can do this check and assignment by using the Switch action. We check the value of the Region function by using the formula: body('List_rows_present_in_a_table')['value'][0]['Region/Area']
And we assign the value for the folder ID to the "folder" variable.
Note: You can find the unique ID's for your email folders by using the Microsoft Graph Explorer at https://developer.microsoft.com/en-us/graph/graph-explorer. Log in with your credentials and give Microsoft permission to manipulate data on your behalf. Then do a "GET"query to "https://graph.microsoft.com/v1.0/users/customerservice@automateofficework.com/mailFolders". This will return data about your top level folders, including your Inbox. If the folders you want to identify are children of the Inbox, then you need to get the ID of your inbox and do a subsequent "GET" query to "https://graph.microsoft.com/v1.0/users/customerservice@automateofficework.com/mailFolders/{TYPE IN THE ID OF YOUR INBOX FOLDER}/childFolders", but actually type in the ID of your Inbox folder.
Lastly, we move the email that we received to the correct folder. Unfortunately, there is no action to do this directly in Power Automate. There is an action to do this for an individual mailbox, but not for a shared mailbox. So instead, we will use the Microsoft Graph which we just used above to get the ID's of the folders. To make a call to Microsoft Graph inside of Power Automate, we use the "Invoke HTTP Request" action. When you first use it, it will prompt you to log in with your username and password and to give Microsoft Graph to manipulate your data on your behalf. Once logged in, we do a "POST" call to "https://graph.microsoft.com/v1.0/users/customerservice@automateofficework.com/messages/{ID OF THE EMAIL GOES HERE}/move". The header is "Content-type":"application/json". And the Body of the request has the ID of the destination folder that we just assigned to our "folder" variable.

Conclusion

That's it. We now have emails that will automatically be placed into appropriate subfolders. Where before we had a person whose full-time job was to manually move emails, we've now automated the bulk of this work. We may still get emails into the Inbox, but these will come from new people who have not been indicated yet in the spreadsheet. Our worker will still need to figure out this new person's region and add them to the spreadsheet. But once done, these will also automatically go into the correct folder.
Comments
You must sign in to comment
Justin said:2023-10-13 18:39:41
It is not possible to base this functionality on an entire email domain in Microsoft Power Automate. You could do this using server side tools.
said:2022-09-08 18:10:25
Is it possible to change the functionality to make it based upon an email domain versus the full email address?
Justin said:2022-01-05 11:28:08
Do you have a different set of tools that you would use to solve this scenario? Let us know in the comments, email me at justin@automateofficework.com, or let us know in our various social media channels.
We use cookies to help run our website and provide you with the best experience. See our cookie policy for further details.