“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.
@contains(triggerOutputs()?['body/subject'], 'The')
@contains(triggerOutputs()?['body/subject'], 'whole')
@contains(triggerOutputs()?['body/subject'], 'string')
Search for one of the words
You can also search for each word separately. Even if the email subject contains only one of the words, trigger the flow.
@or(
contains(triggerOutputs()?['body/subject'], 'The'),
contains(triggerOutputs()?['body/subject'], 'whole'),
contains(triggerOutputs()?['body/subject'], 'string')
)
You can even combine the conditions together with the AND (a separate row) and OR (all on one row) operators.
Summary
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:.
Hello, Is there a way to trigger the flow only if the name of attached file starts with specifics letters ?
Hello Jen,
you can do that if the email contains only a single attachment:
@startsWith(triggerOutputs()?['body']?['attachments'][0]?['name'],'string')
I don’t think it’s doable for emails with multiple attachments.
How about extracting unknown length of texts from the newly arrived emails and directly save into a SP list? and those Texts in the emails could be aligned to left, OR center-aligned in the middle (within certain background picture). I saw some old forum posts saying need hard code. Example:
Time: 02/02/2022
Address: this can be short or very long
Name: this can be short or long
Thank you, thats a great hint.
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:.
How would this look?
Hello Jarrot,
just enclose the condition in not(…) to reverse it, e.g. @not(contains(triggerOutputs()?[‘body/subject’], ‘RE:’))
great help. thanks.
Hello. That is exactly what I want to do. I just need a precision. Do you insert directly the text of the trigger conditions in the Subect Filter text area ? When I test like that, I have an error : One or more fields provided is of type ‘Null’, a different type is expected.
My trigger conditions : @or(contains(triggerOutputs()?[‘body/subject’], ‘Info Production ‘), contains(triggerOutputs()?[‘body/subject’], ‘Info SNP – Production/Other’))
Thanks for your help.
Sorry for previous question. The form to setup trigger condition(s) is accessible in ‘parameters’ (…) of ‘When a new email arrives V3’ Form.
Thanks a lot.
We are attempting to do this trigger with when an email an email arrives from a shared mailbox V2. There is no V3 for shared mailbox. We are not able to get this trigger to work. Any help is appreciated.
@or( contains(triggerOutputs()?[‘body/subject’], ‘Essay’),
contains(triggerOutputs()?[‘body/subject’], ‘MDMP’),
contains(triggerOutputs()?[‘body/subject’], ‘application’),
contains(triggerOutputs()?[‘body/subject’], ‘submission’)
)
Hello David,
the trigger condition looks fine to me, I’d check if it’s not blocked by something else set in the trigger action directly.
Brilliant tip. Thank you for that. Very handy indeed
Question, in the adaptive card. Is there a way to show the body of the email? Not only the body/subject…. is there a way to show like the first few line of the email or the entire email?
When a new email arrives (V3) is my first step in the flow
Used the trigger condition as contains(triggerOutputs()?[‘body/subject’], ‘The’),
Got the error below while saving
Request to Azure Resource Manager failed with error: ‘{“error”:{“code”:”InvalidTemplate”,”message”:”The template language expression evaluation failed: ‘The template language function ‘contains’ expects its first argument ‘collection’ to be a dictionary (object), an array or a string. The provided value is of type ‘Null’.’.”}}’.
So changed the condition to
contains(triggerOutputs()?[‘body/value’], ‘The’),
The flow got saved without error but does not work on triggering keeps running without any action
When clicked on test button test after selecting historical run nothing happens