cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Larson-JB
Regular Visitor

Advanced Email Routing of Mailflow Based on Email Body in Shared Mailbox

I am having trouble with routing rules and attempting to solve this issue using Power Automate to move emails coming into the inbox of a shared mailbox. We currently use Inbox rules on the shared folder but we keep running into issues of codes being used further down in the email chain and triggering the move rule. There is no way to correctly order these and I do not know of a way to search just a section of the body of the email for a specific trigger so I am attempting to use Power Automate for this.

 

I currently have a list of 40 possible routes an email could go based on trigger codes in the first body of the email. I have the flow working for a single condition for searching for one code. But the conditions fail if I branch to multiple conditions or put a second condition under the "no" of the first condition. I am splitting the email body on the company phone number in the signature line to get the first message body without any reply data to omit previous routing codes and trying to route the new email soley based on the body of the most recent email.

 

What is the best approach for handling this?

 

Flow currently:
Trigger: When email arrives in inbox

Convert email body to HTML

compose - uriComponent(body('Html_to_text'))

compose 2 - split(outputs('Compose_2'),'800-555-6571')

compose 3 - decodeUriComponent(first(outputs('Compose_-_Split_After_Phone_Number')))

initialize - type: string, value: output of compose 3

 

condition - searching the initialized string for codes and move to correct folder

 

What i am wanting to do is

- If first split output contains "ooo", move to "Orders" folder

- If first split output contains "qqq", move to "Quotes" folder

- If first split output contains "rga", move to "Returns" folder

 

The below works for a single condition only.

Mail Route Flow.PNG

3 REPLIES 3
ekarim2020
Super User
Super User

(1) Can you post some examples what the data looks like, and what you are trying to extract from the body text

(2) Routing rules - are you moving emails into folders within same Shared Mailbox? So 'ooo' will be moved in to a folder called Orders  within the same mailbox?

Ellis

ekarim2020
Super User
Super User

We can leverage a SharePoint list and avoid having to 40+ conditions in Power Automate. We can create a lookup table. Given the operating trigger code (e.g.. 'ooo',  'qqq' or 'rga') we want SharePoint to return the routing folder name. I am assuming that the email needs to be moved to a folder within the same shared mailbox.

In the SharePoint list called Routing there are only two columns: Title which stores the operating codes, and Folder which corresponds to a folder name in the shared mailbox:

ekarim2020_0-1629568413750.png

Using a list in this way will allow us to add, change or delete operating codes and folder names without need to update the flow.

We use the Get Items action and search for the operating code using an ODATA filter query. In the example below I use the email's subject line as the operating code - just to keep things simple.

ekarim2020_2-1629569099515.png

The search result from the Get Items action will contain the folder name:

ekarim2020_7-1629570288037.png

 I then use an expression to extract the folder name and store that in a compose action. Finally I move the email to the extracted folder name using the Move email (v2) action:

ekarim2020_8-1629570737028.png

Here is the entire demo flow, which also checks to see if the lookup (Get items action) returned any results:

ekarim2020_6-1629569584455.png

The question now becomes how easily or reliably can you extract the operating codes from the body of the email?

I hope this helps.

Ellis

 

This looks like a comprehensive solution to my issue. I am going to test it out this week and see how it works. But I think this may be the solution I need. Thank you very much!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,107)