Hello Power Users! Hope you guys are doing good.
In this blog, we will see how we can start working with different Outlook connectors and parse the text from an email which we receive in our outlook account.
Few topics discussed in this post:
- Types of Outlook Connectors
- Connecting to Outlook account from flow
- HTML to Text (preview) action
- Steps to parse Email text
In this demo we will send an email from our outlook.com account to self with a body in the below format, and we will fetch the strings “James”, “To parse me and perform string operations” and “Send me the text in quotes”.
To start, go to https://flow.microsoft.com and sign in with your Microsoft or Work Account.
Select Create -> Automated cloud flow and you will see the below window:
Here we can give the flow name and select a trigger which will start the flow. Otherwise we can simply click on Skip.
Upon skipping, we will get an empty flow (as shown below) in which we can still give it a name and select the trigger. For this demo, we have skipped to the empty flow.
Click on Untitled and name the flow as Parse Outlook Email Text or any name of your choice. In the search connectors and triggers searchbox, type “outlook” and from the list of available Connectors, choose Office 365 Outlook or Outlook.com. Then from the list of available triggers for each connector, select “When a new email arrives“.
I will use the below trigger from Outlook.com connector for this demo as I am using my Microsoft account and not a work account.
Sign into your Outlook account when asked.
Give the required access when prompted for.
Note: The below steps will be the same for both account types.
Click on ‘+ New step‘ as seen in the below image.
Search for ‘html to text’ in the search connectors and trigger searchbox. From the list of available actions, select Html to text (preview).
With the help of this action, we will convert the email text which is in HTML to plain text.
Now click on Add dynamic content -> Dynamic Content -> Body.
This step will give us the plain text of the Body of the email.
Now we will calculate the length for the whole string (email body text).
Add a new step. and search for “compose” and select Compose action.
Write the expression as shown below. Click on Ok.
Rename this step to “CalculateContentLength” (some good practice here 🙂 )
We want to get the string “James” which is in between Name: and and Challenge:.
If we have the starting index for “James” which is the index of “ character (quote) and index of Challenge: keyword from the whole string, and returns the text in between these two indices, we will get our first string “James”.
Let’s get the index of ” (quote) which is the starting character of our first string “James”.
Add another Compose action and use the expression: add(indexOf(body(‘Html_to_text’),’Name:’),5)
Also rename it.
Similary, add another compose action and use the expression:
Now time to get the substring. Add another Compose action and use the expression:
With this our flow looks the one shown in the below image:
We will Save the flow and Test it Manually by sending the above sample email to our own outlook account:
Once your email arrives, your flow will start running and upon completion you will see the results as below:
Inorder to check if we have got the correct string “James” which we were trying to fetch, click on OurFirstSubstring step and we can see the output return by this step.
Now we can repeat the same steps from fetching the start index and till the above step to get the other substrings we are looking for.
Here on, we can store these substrings to variables or in other functions and perform all the string related functions.
If you find this post helpful, please stay tuned for more. Thank you.