Parsing Email Text in Power Automate
Parsing out text from formatted emails is a common requirement and there are frequent questions on the Power Automate forums about how to accomplish that requirement. The examples below demonstrate a common scenario.
The requirement in this case is to parse the email address and the account number from the email.
To accomplish this, we'll leverage the Power Automate split() expression. The split() expression creates a comma separated array based on a specified delimiter. In the example below, I am splitting the string in the first compose action using a semicolon as the delimiter.
Now, let's use split() to address our formatted email requirement.
Here is an example of a formatted email body:
___________________________________________________________________
You have received a new request from a customer:
Customer email: jim@abc.com
Account number: ABC4567
Please take action on this request as soon as possible
__________________________________________________________________
We'll accomplish our goal in a number of steps.
The expressions used can be seen in the action comments.
Email Step 1 Action (Compose)
- I am splitting on the word "Account" which creates an array with two elements
- The email address will be contained in the first element
- I use the first() expression to access the first element in the array
Email Action (Compose)
- I split the output of the Email Step 1 action on the text "email:" which creates an array with two elements
- The last() expression retrieves the last element of the array
- The trim() expression is used to clean-up the resulting string and eliminate any spaces or unseen characters
- The email address is not stored in the Email compose action
Now, lets parse out the Account number.
The account number can be accessed by referencing the output of the Account number compose action.
The only difference between parsing out the email and the account number is the text that was used to split on.
In practice, you'll likely be referencing the output of a When an email is received trigger in place of my first compose action.
Finally, please note that while I broke out my expressions into two steps for the email an account number, I could have done each in one single step. I used two steps for the sake of clarity.
*This post is locked for comments