Do you want to filter out emails based on the email’s subject line in Power Automate? In this tutorial, I have explained an example of when a new email arrives subject filter in Power Automate. It will help you to filter emails when a new email arrives based on the subject line using Power Automate flow with different examples.
Scenario:
Recently, I got a requirement to filter the emails based on the subject line and save the email’s attachment into a SharePoint document library. Here, I will show three examples of applying a subject filter when a new email arrives in Outlook using Power Automate.
- For the first example, I will implement a simple email subject filter when a new email arrives; it will save the attachments to a SharePoint document library using Power Automate.
- In the second example, I will show you two different ways to apply subject filter emails, whether the subject line contains a value or not, when a new email arrives using Power Automate.
- In the third example, I will show you two different ways to apply multiple subject filters to email, whether the subject line contains a value or not, when a new email arrives using Power Automate.
When a new email arrives subject filter in Power Automate
Let us see a simple example of “when a new email arrives subject filter in power automate”.
- The subject Filter is not case sensitive; for example, when we enter the subject filter input value as ‘WELCOME’, the flow will run when we receive an email with the subject line of ‘welcome.’
- When a new email arrives subject filter trigger action has an input field called subject Filter and takes the String input value.
In this example, I will show you how to apply a direct subject filter when a new email arrives in trigger action and save the email’s attachment into a SharePoint document library.
To achieve this, follow the below steps:
1. Create an automated cloud flow and select the trigger when a new email arrives (V3) from the trigger actions. Expand the trigger action and choose the parameters as highlighted below:
- Folder: Select the Folder; here, I have selected my Inbox folder presented in Outlook. Then Click Show Advanced options, and choose the below parameters
- Include Attachments: select the yes option.
- Subject Filter: enter the text string of the subject line that you want to filter as a Subject Filter input. Here, I have passed the subject line value as HR.
It will search if the passed subject filter text is contained anywhere within the subject line or not; if it matches, the flow will run; otherwise, the flow will not run.
2. Add a compose data operation and pass the attachment from dynamic content to get the attachment content presented in the attachment. It will automatically add the apply to each control loop. If the email contains multiple attachments, it will get all the attachments.
items('Apply_to_each')?['contentBytes']
Now, choose the create file option for SharePoint from the action triggers.
- Site Adress: from the dropdown list, select the SharePoint site.
- Folder Path: choose the folder path where you want to save the filtered email attachments
- File Name: from the dynamic content value, select the attachment file name.
- File Content: pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose'))
- Save and test the flow. I have sent an email with an attachment from a user ID with the subject line ‘HR DOCUMENTS’.
So the subject line ‘HR DOCUMENTS’ contains the subject filter text ‘HR’. So the flow triggers automatically and runs successfully like below:
Then, it saves the attachment in the selected SharePoint Online document library.
This is how to apply a direct subject filter when a new email arrives in trigger action using Power Automate flow.
Power Automate when a new email arrives subject filter contains
Let us see how to filter emails to apply subject filter emails, whether the subject line contains a value or not when a new email arrives using Power Automate.
In this example, I will show you two different ways (Trigger action, Contains Operator)to apply subject filter emails, whether the subject line contains a value or not, when a new email arrives and save the email’s attachment to the document library.
First way: (Trigger action)
Create an automated cloud flow and select the trigger when a new email arrives (V3) from the trigger actions. select the parameters as highlighted below:
- Folder: From the show picker, select the Folder here; I have selected my Inbox folder presented in Outlook.
- Include Attachments: choose the yes option.
To Add a Trigger Condition, select the When a new email arrives trigger action,
- Click on the Ellipses icon When a new email arrives, trigger action as highlighted below.
- Select the Settings option.
Click +Add under the trigger action, then pass the below expression and click Done.
@contains(triggerOutputs()?['body/subject'], 'Finance')
- Select + new step, add a compose data operation from the dynamic content, and pass the attachment content to get the attachment content presented in the attachments. It will automatically add the “apply to each” control loop.
items('Apply_to_each')?['contentBytes']
From the action trigger, choose the create file option for SharePoint. Pass the required parameters.
- Site Adress: from the dropdown list, select the SharePoint site.
- Folder Path: choose the folder path where you want to save the filtered email attachments
- File Name: Select the Attachment file name from the dynamic content value.
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose'))
Save and test the flow. I have sent an email with an attachment from a testing user ID with the subject line ‘Finance Documents’.
So the subject line ‘Finance Documents’ contains the subject filter text ‘Finance’. So the flow triggers automatically and runs successfully like below:
Then, it saves the attachment document with the attachment content in the selected document library.
When a new email arrives using Power Automate flow, this is one way to apply subject filter emails, whether the subject line contains a value or not.
Second way:(Contains Operator)
In the automated cloud flow, select the trigger when a new email arrives (V3) from the trigger actions. Expand the trigger action and Choose the Parameters as highlighted below:
- Folder: select the Folder, here, I have selected my Inbox folder presented in Outlook from the showpicker.
- Include Attachments: Select the yes option.
Step -2:
Add a condition control and check if the Subject contains the value HR. Select the Subject from the dynamic content, choose the contains operator, and pass the value as HR.
To build a case-insensitive, we must use the tolower() function. This converts any text to all lowercase.
toLower(string('HR'))
Here, I check the condition if the subject line contains the value HR.
- If yes, Select the + new step, add a compose data operation from the dynamic content and pass the attachment content to get the attachment content presented in the attachments.
- It will automatically add the apply to each control loop.
items('Apply_to_each')?['contentBytes']
Add a new step and choose the create file option for SharePoint.
- Site Adress: select the SharePoint site from the dropdown.
- Folder Path: choose the folder path where you want to save the filtered email attachments
- File Name: select the Attachment file name from dynamic content
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose'))
If no, leave it blank.
Save and test the flow. I have sent an email with an attachment from a testing user ID with the subject line ‘hr Documents’.
So the subject line ‘hr Documents’ contains the subject filter text ‘HR’. Here the condition returns the true value because, in the expression, we used the tolower() function, which converts the upper case value to lower case.
So the flow triggers automatically and runs successfully like below:
Then, it saves the attachment document with the attachment content in the selected document library.
This is another way to filter emails to apply subject filter emails whether the subject line contains a value or not when a new email arrives using Power Automate.
Power Automate when a new email arrives subject filters multiple
When a new email arrives using Power Automate, let us see how to apply multiple subject filter emails based on the subject line.
In this example, I will show you two different ways (Trigger action, Contains Operator) to apply multiple subject filters based on the subject line when a new email arrives using Power Automate and save the email’s attachment to the selected document library.
First way:(Trigger action)
Create an automated cloud flow, and select the trigger when a new email arrives (V3) from the trigger actions. Pass the value of the below parameters.
- Folder: Select the Folder; here, I have selected my Inbox folder presented in Outlook from the show picker.
- Include Attachments: Select the yes option.
Add a Trigger Condition, then pass the below expression and click Done
@or(contains(triggerOutputs()?['body/subject'],string('Power Apps')),contains(triggerOutputs()?['body/subject'], string('Power Automate')),contains(triggerOutputs()?['body/subject'], string('Power BI')))
- Select + new step, add a compose data operation, from the dynamic content, and pass the attachment content to get the attachment content presented in the attachments.
items('Apply_to_each')?['contentBytes']
Choose the create file option for SharePoint from action triggers.
- Site Adress: from the dropdown list, select the SharePoint site.
- Folder Path: choose the folder path where you want to save the filtered email attachments
- File Name: from the dynamic content value, select the Attachment file name.
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose'))
Test case -1:
Save and test the flow. I have sent an email with an attachment from a testing user ID with the subject line ‘Power Automate Document’.
The flow triggers and runs successfully because the subject line Power Automate Documents contains Power Automate.
Finally, it saves the attachment to the selected document library. (Power Platform document library)
Test case -2:
I have sent an email with an attachment from a testing user ID with the subject line ‘Power BI Document’.
Once the flow triggers and runs successfully, saves the attachment to the Power Platforms document library.
This is one way to apply multiple subject filter emails based on the subject line when a new email arrives using Power Automate.
Second way: (Contains Operator)
Create an automated cloud flow and select the trigger when a new email arrives (V3) from the trigger actions. Expand the trigger action and Choose the Parameters as highlighted below:
- Folder: select the Folder; here, I have selected my Inbox folder presented in Outlook from the show picker.
- Include Attachments: Select the yes option.
Here, we are going to check three conditions: they are
- If the subject line contains the value Apps, the attachments will be saved to the Power Apps document library.
- If the subject line contains the value Power Automate, then the attachments will be saved to the Powet Automate document library.
- The attachments will be saved to the Power BI document library if the subject line contains the Power BI value.
Case-1: (subject line contains the value Apps)
Add a condition control and check if the Subject contains the value Apps,
- If yes, Select + new step add a compose data operation, from the dynamic content, and pass the attachment content to get the attachment content presented in the attachments.
items('Apply_to_each')?['contentBytes']
Add a new step and choose the create file option for SharePoint.
- Site Adress: select the SharePoint site from the dropdown.
- Folder Path: choose the folder path (I have selected the Power Apps document library)
- File Name: select the Attachment file name from dynamic content
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose'))
If no, leave it blank
Case-2: (subject line contains the value Automate)
Add a condition control and check if the Subject contains the value Automate, if yes,
- If yes, Select + new step add a compose data operation, from the dynamic content, and pass the attachment content to get the attachment content presented in the attachments.
- It will automatically add the apply to each control loop.
items('Apply_to_each_2')?['contentBytes']
Add a new step and choose the create file option for SharePoint.
- Site Adress: select the SharePoint site from the dropdown.
- Folder Path: choose the folder path (I have selected Power Automate document library)
- File Name: select the Attachment file name from dynamic content
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose_2'))
If no, leave it blank
Case-3: (subject line contains the value BI )
Add a condition control and check if the Subject contains the value BI, if yes,
- If yes, Select + new step add a compose data operation, from the dynamic content, and pass the attachment content to get the attachment content presented in the attachments.
- It will automatically add the apply to each control loop.
items('Apply_to_each_3')?['contentBytes']
Add a new step and choose the create file option for SharePoint.
- Site Adress: select the SharePoint site from the dropdown.
- Folder Path: choose the folder path (I have selected the Power BI document library)
- File Name: select the Attachment file name from dynamic content
- File Content: Pass the below expression under the expression tab of the compose data operation from dynamic content.
base64ToBinary(outputs('Compose_3'))
If no, leave it blank
Test case -1:
Save and test the flow. I have sent an email with an attachment from a testing user ID with the subject line ‘Power Apps Documents’.
The flow triggers and runs successfully and saves the attachment to the selected document library. (Power Apps document library)
Test case -2:
Save and test the flow. I have sent an email with an attachment from a testing user ID with the subject line ‘Power BI Documents’.
The flow triggers and runs successfully and saves the attachment to the selected document library. (Power BI document library)
This is another way to apply multiple subject filter emails based on the subject line when a new email arrives using Power Automate.
Power Automate when a new email arrives subject filter wildcard
- Power Automate string functions do not support wildcards. No expressions are available for wildcard matching in Power Automate.
- So, applying a subject filter with wildcard characters in a Power Automate flow is impossible.
Conclusion
I hope you get an idea to filter out emails based on the email’s subject line using Power Automate Flow.
Here, I have shown you three examples of applying a subject filter when a new email arrives in Outlook using Flow.
In the first example, I have shown you how to apply a direct subject filter when a new email arrives in trigger action using flow.
In the second example, I showed you two different ways to apply subject filter emails, whether the subject line contains a value or not, when a new email arrives using Power Automate.
In the third example, I have shown you two different ways to apply multiple subject filters to email, whether the subject line contains a value or not, when a new email arrives using Power Automate Flow.
You may also like:
- Send a Customized email when a new item is created in a SharePoint list using Power Automate
- Send Email Reminders from a SharePoint List using Power Automate
- How to Send an Email with Attachments in Power Automate?
- Send an Email with Attachments from Local Folder using Power Automate
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com