How to apply rules on the junk folder and How to “stop” from moving Emails to Junk or Spam Folder

UPDATE : A more advance flow is described in this new blog.

I use Microsoft for my private mail for many years now, and over the years I receive more and more spam. In most cases redirects all spam to my Junk folder, which is good. But in some cases 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 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 (delete mail that contains certain keywords or part of a sentence) and if a mail is legitimate that it will be automatically forwarded to my Inbox folder.

I tried to find an automatic solution for this. During my search and tries I found out the following:

  • Rules cannot be applied to the Junk folder, only on the Inbox (but you can run it manually in your Outlook Desktop application and select the Junk folder)
  • The Junk mail / Spam filter runs before the Rules
  • You cannot disable Junk mail to be forwarding to Junk Folder in
  • Some rules created in your Desktop application applies only in the Desktop application itself and not in the webmail interface or on other clients like on your phone. (therefor create rules only in your online webinterface)

The Solution

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

Open a browser and navigate to Login with your private Microsoft Account (in my case my account).

If this is the first time you use Microsoft Flow / Power Automate, select your country/region and click Get started

Click My Flows

Click + New and select Automated – From blank

Give your new flow a name, in my case Move Junk to Inbox (with filter). In Choose your flow’s trigger search for and select When a new email arrives (V2). Click Create

If this is the first time you use a flow for your mail, you need to create a connection to first. To do so, click Sign in

Sign in with your Microsoft Account ( account).

Once the connection with is created, the Inbox folder is selected. To change the folder, click the Folder icon on the right.

Select Junk Email

Now it’s time to configure an action on this trigger. Click + New step

Click Condition (Control)

First we need to configure the Condition, in this case this will be the “Spam Filter”. Select Choose a value

You can select various types of Dynamic content, for creating this “Spam Filter”, most of the time I use Body or Subject. In this case I will use Body

Then you can select contains and then a value where you receive Junk mail about (see my examples above). You can create multiple conditions, but if you create more that one condition, make sure the Or statement is selected.

Now it’s time to configure an action if the conditions match the criteria. Under If yes, click Add an action.
Search for and select Delete email.

In the Message Id field, select Message Id

Final step is to Add an action if the Condition did not match. Under If no, click Add an action

Search for and select Move email

As Message Id, select Message Id. For the Folder, select Inbox

And that is all you have to do.

You can add up to 10 lines per condition, if you want to add more conditions, you can add a second “condition set” as an action on the If no condition.


Your email address will not be published. Required fields are marked *

  • THIS is what I have been searching for. I forward my mail to my account instead of using pop/imap due to the slow scheduling and every single mail was getting placed in the junk folder. My mail server does all the spam filtering for me, I don’t need outlook to but was struggling to get anything to go to the inbox without whitelisting everything which is just not practical. I had no idea you could do this with flow, thank you!

    • Do you know how to stop the auth token constantly timing out? (home subscription, not a business one where you can customize). The rules work great but stop functioning quickly due to auth token expiring.

  • I followed your steps, but it is not working.
    When I check my setup against Flow checker option(upper-right), shows no errors and no warnings. Test option (upper-right), I’m not quite sure how to test because if I forward email from my junk folder to myself that email goes to inbox obviously as it see’s myself as the owner, why would I spam myself? I’ve posted for help in the power user’s forum w/ a link to your site as it shows that I am trying to accomplish the same things. Just to be clear.. I am specify, as my hotmail email account.

    • Where you trying to send the unfiltered emails to a different folder?

      I wanted to test this out so added my 10 things, that doesn’t cover anywhere near the amount of spam I get so I wanted everything else to stay in the junk folder. At first I left the “If no” section empty, as I assumed if things didn’t match then they’d be left in the junk. I then tried to tell it to move things to the junk (not really moving them) but that didn’t work either.

      What I have done now is create a new folder – Junk2 – and told the flow to move emails there. It worked! Now I just need to add more conditions.

      • By the “if no” you can add a new condition and repeat the first steps. You can repeat this for about 8 times and then you need to create a new Automatic Rule. So, by the 8th condition I will move the mails to a second Junk folder and let the second Automatic Rule start there.

    • I tried to reply to this last night but the response hasn’t shown up.

      For this to work, you have to tick the boxes on the “condition” page to activate them. Done some testing using a fake email account on “Guerrilla Mail”.

      I would add that it seemed to be case sensitive, so emails containing “casino” would be deleted but emails containing “Casino” would not.

      Finally, the “if no” section doesn’t actually need anything it – unless you want to add more conditions.

  • Hi Robin, thank you very much for sharing this, the solution works very well! Could you please elaborate a bit on the very last sentence? I want to add more than 10 lines to the “spam filter”, but I am not sure how to to this.

    • Sure, when you have added 10 lines, that’s the max for that action, however, you can add another action instead of the action “If yes, move mail to Inbox”. So replace “If Yes, move to Inbox” with other mail condition like in the first step, where you can add another 10 lines.

      • If not moving the residual e mails to the inbox can you instead just create another seperate flow deleting the e mails from junk with another 10 conditions as an alternative?

        • You can create up to 8 conditions with both 10 rules, so total 80 rules per flow. What I do is moving the mail to a second junk folder if not one the rules are applied. From that second folder I run a second Flow with the next rules.

          • Thx.
            I created – a second seperate flow with different name deleting mails with different junk words and seems to be working just fine so thx for this as for the last 36hrs my junk folder has been completely free of junk; something i thought i’d never achieve!

  • Robin, don’t be modest. 🙂 I know something little bit about computers. I’m not a person who can’t send an attachment. E.g. I’ve been using advanced filters on gmail, etc. But I’ve been looking something like this on for years. I have been through all Google for years. You really are spiderman as the comment says. You have my respect. You’re a real specialist. Thank you!!!! Regards Frank.

  • Absolute legend!
    I too forward my personal email onto but everything ends up in Junk. The ability to control the flow of data is very powerful and the document you put together sure helped.

  • Worked the first time. OUTSTANDING! I’ve been searching for this solution ever since Microsoft introduced Office 365 and I switched from Outlook based on local .PST’s to Outlook 365 pointing to Later I migrated my wife’s configuration and she immediately recognized the same ‘aggressive Junk’ problem. Thanks so much for sharing your expertise.

  • Robin, I have been trying to figure this problem out for a long time. No one has the right answer online. You are an absolute hero and a deserve a special place in the afterlife. Thank you so much!

      • Hi Robin, applied this to my old (but still used) hotmail address (which obviously logins in via these days).

        It worked for the night, and I even managed to add a second and third level for extra “bad” terms. But this morning, I’ve work up and found all the regular spam now in my inbox! (Nothing in junk). I mean, this is still almost better than auto junk folder, but now nothing seems to be reacting to the rules? Terms that were getting emails sent straight to the Bin yesterday are now appearing and staying in my inbox.
        I even have the same terms banned in (which usually doesn’t work due to them going straight to Junk), that have been in place for ages, yet still they all end up in my inbox!

  • Oh my God.

    I’ve been looking for this for YEARS since I switched to Gmail.

    Modified this to forward everything to my Gmail address and then labeled those coming in. Not a perfect solution but at least I know I don’t have the 5-10 percent of real e-mails in the Outlook Junk folder getting purged every 10 days.

  • I didn’t know this existed until today, and it works like magic on my hotmail account. I did discover that MS sends a spam to the originating email address promoting PowerFlow. I haven’t decided yet if I like that.

  • This is great! Do you have to check all the boxes under your conditions for this to work? The screenshots show them unchecked. Thanks!

      • Perfect, thank you! This methodology purged 1,000 emails since last night. I was attacked by a Spambot and it has been brutal. This has helped me trash emails using “From-Contains”. Appreciate it!

  • Many thanks for this, I have now managed to move junk emails to my inbox, however my normal filtering rules do not appear to be actioned on those moved junk emails.

    Is there anything else I need to do so that my normal filter rules are then run on the emails that are moved from junk to inbox?

  • In the Netherlands only work or school account are accepted to create a filter in flow. More than half of my mails disappear in the Spam folder, sometimes even official mail from the government. Whenever I buy something for the first time at a web-shop, or someone trying to reach me for the first time, or mails from others who has not send me something for years, they all go in the spam folder. I’m afraid Microsoft will never fix this, they think it is a good thing.

  • Thank you so much for posting this and for making the instructions so easy to follow. I had never used Flow/Power Automate (although coincidentally I was already scheduled to watch a training session on Power Automate today) but was able to do this without a hitch.

    I had several daily emails I subscribe to that suddenly started going to Junk maybe two years ago. and none of the many solutions I tried have worked until this one. It’s been so frustrating. One of them got fixed for about six months by the company dealing with Microsoft directly to correct the problem, but it started happening again a couple of weeks ago. UGH! So very frustrating. I went through your steps yesterday, and this seems to have done the trick.


  • Really Excellent !
    Question : how to make a rule for messages that are in the Spam folder and are Flagged… where and how to find to condition “flagged for follow-up” ?

    So many thanks !!

  • Quick question: How can I delete messages say ‘from’ BITCOIN that land in Junk as applying the filter to From in the conditions I guess doesn’t work as I guess the from only applies to the actual e mail address sent from?

      • Is there any way to have a condition on the Display Name of the From email?

        Trying to automatically delete spam emails from my Junk folder in, I’ve tried the following:
        From: contains “GEICO Auto Insurance”
        …but it doesn’t work because it apparently only searches the email address itself, not the displayed name of the sender.

        Searching the email address is useless, because the spammers use endless variations of email addresses… it’s the displayed name of the sender that is consistent. (Tommy Chong, WalkInTubs, ADT Premier, etc)

        Searching the subject or the body of the email risks false positives, I really just want to search on the sender’s display name.

  • Working from your flow I have created a version that loads a comma-separated file from OneDrive that contains the spam trigger words. I also did a whitelist and a daily report of what was filtered out and why.

    I cannot share the flow in a standard subscription so I made this jpeg image but I can’t post it here because of the spam filter [ironic]

  • Hi,

    Tried to configure auto-delete of particular mails in outlook junk folder.
    Cannot save the flow because of following error:
    ‘Http request failed with unhandled exception of type ‘ArgumentException’ and message: ‘The path variable ‘USERID’ in the UriTemplate must be bound to a non-empty string value. Parameter name: parameters’.’

    Where is it using a parm called userId?

    Thanks for any help you can give.

  • How do you do this with an O365 account? is for personal accounts only and I don’t see any related flows for or Thanks

  • One solution is to just stop using Outlook. I’m honestly getting tired of their crappy filter (or lack of) when it comes to the Junk folder.

  • I am getting this error in the if yes field : Test connection failed. Details: The tenant for tenant guid ‘f8cdef31-a31e-4b4a-93e4-5f571e91255a’ does not exist. Only work or school accounts are supported. clientRequestId: 12d18f09-e4c4-738a-81e1-448eb91e3396 serviceRequestId: 800194fa-3cf7-4251-ba0e-e2c89eae7daf

    Why can’t I finish this flow setup and save it for my hotmail account?

      • I am using a desktop version. Mostly use outlook android app and Google Chrome, but set up all filters on desktop version and began the Microsoft flow tutorial you explained where I eventually received my error message during the ms flow setup.

  • I am also getting the same error: “Test connection failed. Details: The tenant for tenant guid ‘f8cdef31-a31e-4b4a-93e4-5f571e91255a’ does not exist. Solo se admiten las cuentas profesionales o educativas. clientRequestId: a9ec1b7e-3add-1d4e-78bc-3de1421ecfb4 serviceRequestId: c9b462ba-8363-4ab2-9c4d-978ed4209000”.

    Is there a work around?

    Thanks in advance!!

  • This is brilliant! Been having issues with emails forwarded to Outlook from another account going into Junk. Created a Flow in Power Automate to move everything from Junk back to Inbox,

    Thank you!

About Robin Hobo

I am a Technology Specialist Cloud Endpoint working for Microsoft. I am specialized in Microsoft Intune, Azure Virtual Desktop (AVD), Windows 365, Windows 11 and Azure AD. Also interested in mental health, NLP and personal development.

For more information, see my LinkedIn profile.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.