Use Power Automate and AI prompts to automatically classify emails

Table of Contents

Manually sorting incoming emails can be time-consuming and prone to error. All companies have at least one team that needs to check emails regularly and classify them based on some type of criteria. One example is an Accounts Payable (AP) inbox, where messages may include invoices, account statements, payment status requests, or even promotional content. With Power Automate and AI prompts, this process can be automated, and we can have the Power Platform classify and organize emails in the back end, reducing human intervention to little or none.

Use case description

Let’s suppose we have an AP shared mail box, where gn organization receives a high volume of emails daily. Currently, team members manually review each email and categorize it into 5 categories:
  • Invoices (OCR)
  • Account Statements
  • Payment Status Requests
  • Advertisements/Ignore
  • Other
This is how the mailbox looks:



We want to automate email classification and email assignment to each folder by using Power Automate, with AI prompts (AI Builder / Copilot).

Solution description

To automate the classification of incoming emails in the AP mailbox described previously, we will build a Power Automate flow that uses an AI prompt to analyze each message and determine its category. The solution consists of two main parts:

  1. Create the prompt: we will create a custom text-based prompt. The prompt will analyze each email’s body and return two key values:
    1. Category name (one of: “Invoice (OCR)”, “Account Statement”, “Payment Status Request”, “Advertisement/Ignore”, or “Other”)
    2. Mailbox folder ID (corresponding to the folder where the email should be moved)

Design / Build the workflow: connect the trigger to AP mailbox, call the AI prompt and move to the final folder.

Step 1. Create Prompt

The prompt is the most important part of this automation, the more specific, the better.

This is an example of how the prompt can be built to have the model classify the email and return the folder id:

				
					You are tasked with classifying emails based on the text content of their body into one of five categories: "OCR”, “Account Statement”, “Payment Status Request”, “Advertisement/Ignore”, or “Other”.

These are the ids for each category

OCR
Id::AAMkADc0Y2MyZDliLWRiMmQtNGU2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6GNsjMzT7z3D6TxF4IlAANNg29qAAA=

Account Statement
Id::AAMkADc0Y2MyZDliLWRiMmQtNGU2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6GNsjMzT7z3D6TxF4IlAANNg29sAAA=

Payment Status Request
Id::AAMkADc0Y2MyZDliLWRiMmQtNGU2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6GNsjMzT7z3D6TxF4IlAANNg29rAAA=


Advertisement/Ignore
Id::AAMkADc0Yrweuirewiurewrewre2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6GNsjMzT7z3D6TxF4IlAANNg29rAAA=

Other
Id::AAMkADc0Yrweuirewiurwrewre2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6G00d89s99dsadsadaslAANNg29rAAA=


### Instructions:
1. Analyze the text content of the email body ({body-input}) and email subject ({subject-input}) carefully. 
2. Determine the most appropriate category for the email based on its content:
- **OCR**: Emails related to new invoices from supplier.
- **Account Statement**: Emails containing account statements or financial summaries.
- **Payment Status Request**: Emails involving payment inquiries or questions about payments.
- **Advertisement/Ignore**: Emails that are advertisements, promotions, or should be ignored.
- **Other**: Emails that do not fit into any of the above categories.
3. Assign exactly one category to each email based on the best match.
4. Provide a brief explanation or justification for the chosen category.

### Output Format:
Respond with a JSON object containing:
- "category": The assigned category (one of the five specified). 
- "id": The folder id that belogns to the identified category
-   "justification": why this category was picked

Example:
```json
{
"category": "OCR",
"folderid": "Id::AAMkADc0Y2MyZDliLWRiMmQtNGU2MC05NmM1LTZiMzkzM2ZmOGE2ZAAuAAAAAADQUdjhx_3GQJ-wM9Ra9wJpAQDjN6GNsjMzT7z3D6TxF4IlAANNg29rAAA=",
  "justification": ""
}
```

				
			

There are two ways to create prompts that will be used in Power Automate:

From the AI Builder page (AI Hub)

Go to the AI Builder (AI Hub) page and click on prompts:

 

Automate tasks that slow you down

Free up your team’s time and focus on strategic work with digital and robotic automation.

Click on Build your own prompt

 

You can use Copilot to help generate a prompt or you can create it yourself.

 

Use “/” to add dynamic data, in this case: Subject and Body content

 

This is how the final prompt will look:

Test your prompt and save:

From inside the Power Automate flow itself.

You can also create prompts inside the Power Automate workflow designer, look for the “Run a prompt” action and there will be an option to create a new custom prompt from there.

 

The same pop-up and options as in the AI Builder page will show. Follow the same steps as above.

Step 2. Create workflow and add trigger

Make sure to complete the following steps

  1. Go to the Power Automate maker portal and create a new automated cloud flow.
  2. Add the “When a new email arrives in shared mailbox (v2)” trigger.
  3. Select the original mailbox address.

Make sure that the user authorizing the connection has access to the shared mailbox!

Step 3. Add custom prompt action

Add a new action in the workflow, look for “Run a prompt”

 

In the next panel, select the prompt you just created, and the input parameters will show up (body and subject), these can be filled out from Power Automate’s dynamic content:

Step 4. Add “Move email (v2)” action

Add a new action in the workflow, look for “Move email (v2)”.

Once the action is selected, you will be prompted 3 parameters:

Is your business ready for automation?

Automate processes with Microsoft Power Platform.

  1. Message ID: use message ID from the trigger’s dynamic content.
  2. Folder: use dynamic content from the “Run a prompt” action.

Original Mailbox Address: select your ap mailbox.

You’re all set!

Send an email to the shared mailbox and see magic happen!

Email example:

After the flow has run, the email will be automatically classified and move to the corresponding folder

How our Power Automate and Agentic automation services can help

Automating email classification is just one example of how workflows can transform manual processes into self-managing systems, but there are many more use cases where these types of automations can be applied. With our Power Automate and Agentic Automation services, we help organizations design solutions that use AI prompts, Power Platform connectors, and decision-based logic to handle routine tasks.

Whether you have some ideas in mind or if you’d just like to have a conversation to learn what we’ve done on intelligent automation, contact us, we’ll be more than happy to have a conversation and see how we can be of help for your team.

Author
Power Platform Consultant | Business Process Automation Expert
Microsoft Certified Power Platform Consultant and Solution Architect with 4+ years of experience leveraging Power Platform, Microsoft 365, and Azure to continuously discover automation opportunities and re-imagine processes.