Search for multiple words in the incoming email subject (Power Automate)
Posted On October 24, 2021
“How can I specify multiple words in the email subject in the ‘When a new email arrives’ Power Automate trigger, not just a single string?”
The trigger ‘When a new email arrives’ has a field called ‘Subject Filter’. In that field you can define a string that must be part of the email subject for the flow to trigger. If it’s not in the subject, the flow won’t run. But it’s just a single field expecting the whole string: all the words, in the specified order. If there’re 3 words, the subject must contain all 3 words, with the same separator, in the same order. Having as little as an extra space between the words won’t trigger the flow. Similar to that, it’s not possible to use the field for an OR condition trigger (wordA or wordB).
This post is about adding such possibilities in the ‘When a new email arrives’ trigger.
Use trigger conditions to check the subject
The ‘Subject Filter’ works as a trigger condition in the flow. It’ll check if the subject contains the string, and if it does, it’ll trigger the flow. The only difference is that this one is available directly on the trigger form.
Rewritten to standard trigger condition it would look as below. It’s just one extra row with the AND relationship to the other trigger conditions.
@contains(triggerOutputs()?['body/subject'], 'The whole string')
Knowing this, you can reproduce and extend the ‘Subject Filter’ as needed.
Search for all words, ignore order or separators
It doesn’t have to be just a single condition looking for the whole string. You can search for each of the words separately. The subject must have all of them, but their position doesn’t matter.
You can even combine the conditions together with the AND (a separate row) and OR (all on one row) operators.
If you use the ‘When a new email arrives’ trigger in Power Automate, you’re not limited to the ‘Subject Filter’ when searching for multiple words. It’s just a predefined trigger condition moved to the trigger form. And since it’s a trigger condition, you can ignore it, and build your own trigger conditions. The final combination of AND and OR conditions to trigger the flow is up to you.
The same approach can be used also to ignore emails with a specific subject. For example, to skip all replies or forwarded emails check that the subject does not contain RE: or FW:.