top of page
Writer's pictureEd G.

Expression Interlude - Excluding Forwards and Replies in eMail Triggers with Power Automate / Flow

Up until recently, I hadn't spent much time with trigger conditions, but a recent request in the community had me toying around with it, so I'm sharing some findings here. The initial request (which, I think, would be fairly common) was to have a flow in Power Automate trigger off of a new email, but not if it was a reply or a forward...only an original message. Don't feel like this is the only way to do this, one of my favorite aspects of Power Automate is the flexibility. Here we go...

 

Spoiler Alert


Doing things a bit different this time, I'm going to lead off with the complete expression, and then deconstruct it as we go.

@and(not(startsWith(triggerOutputs()?['body/subject'],'FW:')),not(startsWith(triggerOutputs()?['body/subject'],'RE:')))

Note that trigger conditions need to start with @, unlike the regular expressions inside of an action.

To get to the trigger conditions, click the ellipses ('...') at the top right of your trigger and click on Settings. This will open up the dialogue below where you can set the conditions near the bottom.

 

Let's startsWith the Middle


While the "Subject Filter" of the eMail trigger is a great way to look for items that contain a word or phrase, that field doesn't let us specify where in the string we want to focus, and also we can't easily pass eMails that do not contain the key phrase. The startsWith() syntax is startsWith(<Where to look>, <what to look for>), and by wrapping the not() around that, we are telling Power Automate if 'the thing' begins with this 'string', then we're not interested.

@not(startsWith(triggerOutputs()?['body/subject'],'FW:'))

The expression above will make sure that I don't trigger the flow on any emails where the subject begins with "FW:" (note the colon, as well). Now I just need to add the same thing for replies.

 

And Or, Ian?


Because I wanted to reject the email if the subject began with FW: or RE:, I first tried wrapping both of the expressions with an or(). I quickly found out that this would let any eMail through and I think this is why: With an "or", we're saying to only trigger the flow if it doesn't start with FW: or if it doesn't start with RE:. So, just about any subject would, at least, be meeting one of those conditions and the flow would be triggered. When I used and(), only the correct emails would trigger the flow. I'll admit, this was more trial and error (and error, and error) than logic for me, but that journey is what makes these things fun.

 

Try. Fail. Learn. Repeat.


If you haven't already. be sure to check out my podcast with MS Dynamics World below.

Also, If you're just getting started in Microsoft Power Automate and are looking for a quick guided-learning session, find my Micro-Job on Collab365. We can chat about what is getting in the way of your flow, and I can point you in the right direction.

Until then, get in, make mistakes, learn some things, and have fun!

4,862 views2 comments

Recent Posts

See All

2 Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Brittney Kakie
Brittney Kakie
Jan 20, 2023

This was explained so well, thank you!

Like

Tyler Kolota
Tyler Kolota
Aug 18, 2022

Anyone looking for a solution to this that can't easily be messed up by users, try a trigger condition formula like...

@not(contains(triggerOutputs()?['body/bodyPreview'], concat('<', triggerOutputs()?['body/from'], '>')))
Like
bottom of page