How to apply Outlook.com rules on the Junk folder with Power Automate

How to apply Outlook.com rules on the Junk folder with Power Automate

I use Microsoft Outlook.com for my private email for many years now, and over the years I receive more and more spam. In most cases Outlook.com redirects all spam to my Junk folder, which is good. But in some cases, Outlook.com also redirects legitimate messages to my Junk folder, and this force me to scan my Junk folder on legitimate messages every few days (default retention policy of Outlook.com let Junk items expire in 10 days).

If I find legitimate/”no-junk” mails between dozens of junk mails in my Junk folder, I can, for example, add the sender to the “Save sender list” so that it will not be forwarded to the Junk folder the next time. But I don’t what to check my Junk folder every few days, what I wanted to realize was to filter the Junk mail folder. Delete mail that contains certain keywords in the subject or body, and if a mail is legitimate that it will automatically be forwarded to my Inbox folder. As a second requirement I wanted an easily way to add new keywords to the filter.

I found the solution to realize this in Microsoft Power Automate. Everyone with a Microsoft Account (Outlook.com / Hotmail.com / Live.com) have access to the free version of it, and you can perfectly use it to apply Mail rules as I will show step-by-step below.

Step 1: Create a text file on your OneDrive

Open Notepad and save the (empty) file on your OneDrive. In my case I will save it in the root of my OneDrive but you can also save it in another folder of your choice.

No alt text provided for this image

Now add the words to the file for the spam filter. Emails that contains this words in the subject or body (depending on the flow configuration) will be deleted (in this case). Place a semicolon ( ; ) between every word of words (see example above) and save the file.

Step 2: Create the Flow

Open a browser and navigate to https://powerautomate.microsoft.com/ and login with your Outlook account.

No alt text provided for this image

On the left side, click Create and next, click Automated cloud flow.

No alt text provided for this image

Give the flow a name, in this case I will give it the name Spam Filter. Select the trigger When a new email arrives (V2) (Outlook.com). If you are using Microsoft 365 - Exchange Online select the V3 version.

Click Create

No alt text provided for this image

If this is the first time you create a flow with triggers to your email, you need to create the Connection first. To do so, click the Sign in button and login with your Outlook credentials.

No alt text provided for this image

Click the Folder icon on the right.

No alt text provided for this image

Select the Junk Email folder

No alt text provided for this image

Click Next step

No alt text provided for this image

Select the Build-in tab and select Variable

No alt text provided for this image

Select Initialize variable

No alt text provided for this image

Fill in the following information:

Name : Empty

Type : String

Value : <keep empty>

Click the 3 dots button in the top right corner and click on Rename

No alt text provided for this image

Give it the name EmptyString

No alt text provided for this image

Repeat this step for the following two Initialize variable:

Initialize variable name (rename action) : SearchTerm

Name : SearchTerm

Type : String

Value : <keep empty>

and

Initialize variable name (rename action) : InitTestResult

Name : TestResult

Type : String

Value : <keep empty>

Make sure you have all three the Initialize variable as shown below.

Click New step

No alt text provided for this image

Search for OneDrive and select Get file content using path

No alt text provided for this image

If this is the first time you use OneDrive with Flow you need to create the Connection first. To do so, click the Sign in button and login with your Outlook credentials.

No alt text provided for this image

Click on the Folder icon on the right hand side and select the “spamfilter” text file.

No alt text provided for this image

Rename this step to LoadWordList

No alt text provided for this image

Click New step

No alt text provided for this image

Open the Built-in tab and select Variable

No alt text provided for this image

Select Initialize variable

No alt text provided for this image

Create the following Initialize variable:

Initialize variable name (rename action) : ParseList

Name : eachRow

Type : Array

Click in the Value field

No alt text provided for this image

Open the Expression tab and create the following expression:

split(outputs('LoadWordList')['body'],';')

Click OK

No alt text provided for this image

Click Next step

No alt text provided for this image

Open the Built-in tab and select the Apply to each action.

No alt text provided for this image

Rename the action to blackListLoop. Click the Select an output from previous steps bar and select eachRow

No alt text provided for this image

Click Add an action

No alt text provided for this image

Select the Built-in tab and select Variable

No alt text provided for this image

Select Set variable

No alt text provided for this image

By Name, select SearchTerm. Click in the Value box and open the Expression tab. Create the following expression:

toLower(items('blackListLoop'))
No alt text provided for this image

Click Add an action

No alt text provided for this image

Select Condition

No alt text provided for this image

Click in the Choose a value box and open the Expression tab. Click on toLower(text). The expression toLower() is now set with cursor active between the parentheses. Don’t click OK, but open the Dynamic content tab.

No alt text provided for this image

If you want to filter on text in the body of the mail, select Body. The following expression is now created:

toLower(triggerOutputs()?['body/Body'])

Click OK

No alt text provided for this image

Select contains, and in de Choose a value box, select SeachTerm

No alt text provided for this image

You can repeat the steps for the subject if you want to filter on that too. The expression for the subject will be:

toLower(triggerOutputs()?['body/Subject'])

If you create two or more conditions, make sure you set the conditions to Or (see screenshot above).

In the If yes window, click Add an action

No alt text provided for this image

Open the Built-in tab and select Variable

No alt text provided for this image

Select Set variable

No alt text provided for this image

Choose the variable TestResult. Click in the Value box and select Current item

No alt text provided for this image

Click New step (outside the blackListLoop)

No alt text provided for this image

Select Condition

No alt text provided for this image

Rename the action to Result. Configure the action as follows:

TestResult – is not equal to – Empty

In the If yes window, click Add an action

No alt text provided for this image

In my case I want to Delete the email if one of the words from the file on OneDrive is in the subject or body of the email. Therefor I search for Outlook.com and select Delete email as the action.

No alt text provided for this image

In the Message Id box select Message Id

No alt text provided for this image

In the If no window, click Add an action

No alt text provided for this image

I want mail to move to another folder after the flow has been triggered (and no words have been found in the text file). This so I know it was not filtered by any words. Therefor I have created a “JunkMail NotFiltered” folder in my inbox. But you can also move it to your Inbox folder.

Search for Outlook.com actions and select Move email

No alt text provided for this image

In the Message Id field, select Message Id. In the Folder box browse to the desired target folder.

Finally, click Save

If everything is configured correctly, your flow looks like this:

No alt text provided for this image

Hope it will help you with your “spam problem”. You can use this same flow to filter email in your Inbox for example.

#PowerAutomate #CommunityRocks #Microsoft #Outlook #spamfilter #hotmail #flow #stopspam

This is amazing. Just needed the part of getting email out of this oversensitive spam filter. Thank you very much

回复
Chuck Getty

Owner at Getty Computer Services, Getty Enterprises LLC

3 个月

I was hoping that this would work for me, but Power Automate does not allow personal Microsoft Accounts. You must have a work or school account. ??

回复
Aleksandar LUKIC

Enterprise Architect - Individual life insurance sector at iA Financial Group (Industrial Alliance)

9 个月

Thank you. Exactly what I planned to do. A chance that I found your post. It saved me a lot of time ! Also, in order to share an improvment or idea, I added a step in the last Yes step in order to keep track of matched words. It add a line in an Excel table in order to keep track of what is going on. It will allow me to delete words that are never matched and also, maybe, to diagnose a mail that shouldn't have been deleted.

回复
Victor Ivanidze

Owner, IvaSoft

10 个月

This freeware flow is much easier to install: https://ivasoft.com/deleteitemsinjunkfolderflow.shtml

Adam Hodge

Tech Innovator & Strategist | Low-Code & Digital Transformation Expert | Consultant, Developer, System Architect & Pre-Sales Manager

1 年

Anyone know a way to get the sender display name in the trigger output? It seems we can only get the email address? Robin Hobo For the persistent spam I'm getting (in the junk folder), that field would eliminate most of it. I've noticed a flood of spam from ".onmicrosoft.com" accounts recently. You can clear those with a trigger filter.

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了