Extracting key values from an Email

Posted by

Emails often contain critical data, such as order numbers, customer feedback, or tracking information. Extracting this data manually can be time-consuming and error-prone. With Power Automate, you can automate the extraction process, ensuring accuracy and freeing up your valuable time for more strategic tasks.

Sample Email

Dear Alan,

We are pleased to inform you that your contract details have been updated. Please find the contract information below:

Contract Number: CN-12345

Email Address: john.doe@example.com

Contract Start Date: 2023-12-31

If you have any questions or need further assistance, please do not hesitate to contact our support team at support@example.com.

Thank you for your continued partnership.

Best regards,

Power Automate

Here’s a general approach using Power Automate:

  1. Trigger: Start with a trigger that specifies when your flow should run. For example, you can use the “When a new email arrives” trigger if you want to extract information from incoming emails.
  2. Get Email Content: Add an action to get the content of the email. Use the appropriate connector depending on your email provider (e.g., Microsoft Outlook, Gmail, or Office 365 Outlook).
  3. Parse Email Body: To extract values from the email body, you’ll typically need to parse the content. The method you use for parsing depends on the structure of the email and the information you want to extract. Common methods include:
    • HTML Parsing: If the email body is in HTML format and the information is enclosed in HTML tags, you can use the “HTML to Text” action to convert the HTML to plain text. Then, you can use text functions to extract the desired values.
    • Text Parsing: If the email body is in plain text or you want to extract text values, you can use text manipulation functions like “Split” or “Substring” to extract specific portions of the email content.
    • Regular Expressions: If the information you want to extract follows a specific pattern, you can use regular expressions to search and extract data from the email body. Power Automate supports regular expressions through the “Matches” function.


Since you receive several emails, you might want to add a filter on your trigger. In the example provided I am looking for emails with subject “Contract Details”. Here are some examples of how you can set up filters:

  • Filter by Subject: You can filter emails based on their subject. For example, you can set the condition to trigger only when the subject contains a specific keyword.
  • Filter by Sender: You can filter emails based on the sender’s email address. This allows you to trigger the flow only for emails from specific senders.
  • Filter by Importance: You can filter emails based on their importance level, such as “High” or “Low.”
  • Filter by Attachments: You can filter emails that have attachments or attachments of a certain type.
  • Filter by Received Time: You can filter emails based on when they were received, such as within the last 7 days.

HTML to Text action converts the HTML formatted body to plain text. You can then use a series of expressions to extract the key data from your email.

By reviewing the Email body we see that the Contract Number lies between two headings Contract Number and Email Address. Hence we use an expression to extract the value as shown below:

trim(first(split(last(split(body('Html_to_text'),'Contract Number:')),'Email Address')))

Repeat the same for all keywords

trim(first(split(last(split(body('Html_to_text'), 'Email Address:')), 'Contract Start Date')))
trim(first(split(last(split(body('Html_to_text'), 'Contract Start Date:')), 'If')))

Final Flow


  1. Dear sir, please help on this flow whenever I receive an email the attachment should be stored in th SharePoint.
    Based on the mail received date a new folders should get created automatically for year and sub folders for month and the attachment should be stored in the monthly folders respective folders automatically

Leave a Reply

Your email address will not be published. Required fields are marked *