How to Create Email Filters

Gmail, Outlook, Apple Mail and Yahoo — plus a free filter creator

An email filter is a saved search with an action attached: when a new message matches, your email service labels, archives, forwards or deletes it for you. Build one with the free creator below and test it in Gmail, or jump to the steps for your email app.

By the KeepKnown team · Updated

Free tool

Free email filter creator

Fill in what to match and what should happen. You get the Gmail search to test, a mailFilters.xml file to import into Gmail, and the same rule for Outlook.

Runs entirely in your browser. Nothing you type is sent to KeepKnown or saved.

1. Match messages
Size
MB
2. Choose what happens
In Gmail this is the Also apply filter to matching conversations box. It isn't stored in the import file, so the steps tell you when to tick it.
See the result

Gmail search

Add a condition to build the search.

Opens in your first signed-in Gmail account. Check the results before you create the filter.

  1. In Gmail, select Show search options, the sliders icon at the right end of the search box.
  2. Select Create filter.
  3. Tick: Tick the actions you want. Choose at least one in the form.
  4. Tick Also apply filter to matching conversations.
  5. Select Create filter.

Forward it to only appears after you add and verify the address in Settings, See all settings, Forwarding and POP/IMAP. Forwarding applies to new mail only.

mailFilters.xml for Gmail

Download the file, then import it into Gmail.

  1. In Gmail, select Settings (the gear icon), then See all settings.
  2. Open the Filters and Blocked Addresses tab.
  3. At the bottom of the page, select Import filters.
  4. Choose mailFilters.xml, then select Open file.
  5. Check the filter Gmail lists and select Create filters.

An imported filter acts on new mail. To sort mail you already have, edit the filter afterwards and tick Also apply filter to matching conversations.

Preview the file

The same rule in Outlook

Add a condition and an action Outlook supports to see the steps.

Using classic Outlook for Windows? Follow the classic Outlook steps with the same conditions and actions.

Try an example:

All 10 examples

How to create a filter in Gmail on a computer

Gmail builds every filter from a search. You describe the messages, check that the search finds the right ones, and then tell Gmail what to do with them.

  1. Open Gmail in a browser on your computer.
  2. In the search box at the top, select Show search options, the sliders icon at the right end of the box.
  3. Fill in only the fields you need: From, To, Subject, Has the words, Doesn't have, Size or Has attachment.
  4. Select Search and look through the results. If they include mail you want to keep, tighten the criteria and search again.
  5. Open search options again and select Create filter.
  6. Tick the actions, such as Skip the Inbox (Archive it), Apply the label or Never send it to Spam.
  7. To sort the mail you already have as well, tick Also apply filter to matching conversations.
  8. Select Create filter.

Shortcut from a message: tick the box next to an email, select More (the three dots), then Filter messages like these. Gmail fills in the sender for you.

Want a sender gone rather than sorted? Blocking them in Gmail sends their future mail to Spam without a filter. A filter with Delete it does the same for a whole domain.

What each Gmail filter action does

Action What happens
Skip the Inbox (Archive it) The message goes to All Mail without appearing in the inbox. Search still finds it.
Mark as read The message arrives already read, so it doesn't add to your unread count.
Star it Adds a star so the message shows in Starred.
Apply the label Adds a label you choose or create. A message can have several labels.
Forward it to Sends a copy of new matching mail to an address you have verified in Gmail.
Delete it Moves the message to Trash. Gmail empties Trash after 30 days.
Never send it to Spam Keeps matching mail out of Spam, even when Gmail's spam filter would flag it.
Always / Never mark it as important Overrides Gmail's importance marker for these messages.
Categorize as Puts the message in the Primary, Social, Updates, Forums or Promotions tab.

Search operators you can use in a filter

You can type these in Has the words, or straight into the search box before you select Create filter. Write OR in capitals.

Operator Example Matches
from: from:amazon.com Mail from any address at amazon.com
to: to:me Mail addressed to you
subject: subject:(invoice OR receipt) A subject containing either word
OR or { } {a@example.com b@example.com} Either term
- -unsubscribe Messages without the word
" " "order shipped" The exact phrase
has:attachment has:attachment Messages with any attachment
filename: filename:pdf Attachments of a type or name
larger: / smaller: larger:10M Messages over or under a size
list: list:news@example.com Mail from a mailing list
deliveredto: deliveredto:you+shop@gmail.com Mail sent to one of your addresses or a +alias

Operators about a message's state, such as is:unread or older_than:30d, are only useful for a one-time cleanup: a filter checks each message once, when it arrives. The full list is in the Gmail search operators guide.

How to create a Gmail filter on iPhone or Android

The Gmail app for iPhone and Android can't create or edit filters. You can still make one on your phone by opening Gmail's desktop site in a browser.

  1. Open Safari or Chrome on your phone and go to mail.google.com.
  2. Switch to the desktop site. In Safari, open the page menu in the address bar and tap Request Desktop Website. In Chrome, open the menu and choose Desktop site (Android) or Request Desktop Site (iPhone).
  3. Sign in if asked, then follow the computer steps above. Zoom in or turn the phone sideways if the controls are small.
  4. Go back to the Gmail app. The filter is already working there.

Gmail runs filters on Google's servers, not on your device. A filter you create anywhere applies to new mail on every device: the Gmail app, the website and any mail app connected to the account.

How to apply a Gmail filter to existing emails

Filters act on new mail as it arrives. To run one on the mail already in your account, tick Also apply filter to matching conversations before you select Create filter. For a filter you made earlier:

  1. Select Settings (the gear icon), then See all settings.
  2. Open Filters and Blocked Addresses.
  3. Find the filter and select Edit, then Continue.
  4. Tick Also apply filter to matching conversations.
  5. Select Update filter.

Labels, archiving, stars, categories and read status apply to old mail. Forwarding never does. If the filter deletes mail, old matches go to Trash too, so check the search results first. More detail is in applying Gmail filters to existing emails.

How to edit or delete a Gmail filter

  1. In Gmail on a computer, select Settings (the gear icon), then See all settings.
  2. Open Filters and Blocked Addresses. Every filter is listed with its criteria and actions.
  3. To change one, select Edit, adjust the criteria, select Continue, change the actions and select Update filter.
  4. To remove one, select Delete and confirm with OK.

Deleting a filter doesn't move any mail back. Messages it archived, labeled or deleted stay where they are.

Back up or copy filters: on the same page, tick the filters you want and select Export to download a mailFilters.xml file. Use Import filters at the bottom of the page to add them to another Gmail account. The creator above makes files in the same format.

How to create a rule in Outlook on the web and new Outlook

Outlook calls filters rules. These steps work in Outlook.com, Outlook on the web for Microsoft 365 and the new Outlook for Windows and Mac.

  1. Select Settings, the gear icon at the top right.
  2. Select Mail, then Rules.
  3. Select Add new rule and type a name for it.
  4. Under Add a condition, choose what to match, such as From, Subject includes or Has attachment. Add more conditions if every one must match.
  5. Under Add an action, choose what happens, such as Move to, Mark as read, Categorize, Forward to or Delete.
  6. If some matching messages should be left alone, select Add an exception.
  7. Stop processing more rules is ticked by default. Clear it if later rules should also act on the same messages.
  8. Select Save.

Shortcut: in new Outlook, right-click a message, choose Rules, then Create rule. To run a rule on mail you already have, go to Settings, Mail, Rules and select the run icon next to it.

New Outlook doesn't run rules for Gmail, Yahoo or iCloud accounts added to it. Create those filters in the provider's own settings instead.

For ready-made recipes and fixes when a rule stops running, see the Outlook rules guide. To stop a sender outright, block them in Outlook instead of writing a rule.

How to create a rule in classic Outlook for Windows

  1. On the Home tab, select Rules, then Manage Rules & Alerts. You can also find it under File.
  2. Select New Rule.
  3. Under Start from a blank rule, select Apply rule on messages I receive, then Next.
  4. Tick the conditions, such as from people or public group or with specific words in the subject. Click each underlined value to fill it in, then select Next.
  5. Tick the actions, such as move it to the specified folder, fill in the underlined values and select Next.
  6. Add any exceptions and select Next.
  7. Name the rule. To sort the mail already in your inbox, tick Run this rule now on messages already in "Inbox". Select Finish, then OK.

Outlook marks some rules as client-only. Those run only while Outlook is open on that computer.

How to create a rule in Apple Mail on a Mac

  1. In Mail, choose Mail > Settings and select Rules. On macOS Monterey and earlier, it's Mail > Preferences.
  2. Select Add Rule and type a description.
  3. Choose whether any or all of the conditions must be met, then set them, for example From contains example.com.
  4. Under Perform the following actions, choose what happens, such as Move Message to a mailbox. Select the add button for more than one action.
  5. Select OK. Mail asks whether to apply the rule to messages already in your mailboxes: choose Apply or Don't Apply.

To run your rules on existing mail later, select the messages and choose Message > Apply Rules. Rules made in Mail on a Mac run only while Mail is open on that Mac.

iCloud Mail on the web

The Mail app on iPhone and iPad has no rules. If you use an iCloud email address, create rules on iCloud.com instead: they run on Apple's servers and apply on every device.

  1. Go to icloud.com/mail and sign in.
  2. Select the Settings button at the top of the Mailboxes list, then choose Settings.
  3. Select Rules, then Add.
  4. Name the rule, choose which messages it applies to under Message, and what happens under Action.
  5. Select Add.

iCloud allows up to 500 rules, applies them in list order, and can take up to 15 minutes to start using a new or changed rule.

How to create a filter in Yahoo Mail

  1. Select Settings, the gear icon, then More Settings.
  2. Select Filters, then Add new filters.
  3. Name the filter.
  4. Set the rules, such as From or Subject, and what the text contains.
  5. Choose the folder matching mail should move to, or create a new one.
  6. Select Save.

Yahoo filters can only move mail to a folder, including Trash. You can have up to 500. When two filters match the same message, the one higher in the list wins, so use the arrows on the Filters page to reorder them.

10 filters worth creating

Each one is a starting point. Select Load into the creator, replace the example addresses, and test the search in Gmail before you create the filter.

  1. Newsletters and mailing lists

    Nearly every newsletter has an unsubscribe link, so the word catches most of them. Run the search first: some receipts and account emails contain it too.

    Search
    unsubscribe
    Then
    Skip the Inbox (Archive it) · Apply the label: Newsletters
  2. Receipts and invoices

    Collects purchase confirmations under one label and keeps them out of the inbox. Add the words your shops and suppliers use in their subject lines.

    Search
    subject:(receipt OR invoice OR "order confirmation")
    Then
    Skip the Inbox (Archive it) · Apply the label: Receipts
  3. Everyone at one company

    Replace example.com with the company's domain. It covers every address at that domain, including people who write to you for the first time.

    Search
    from:@example.com
    Then
    Apply the label: Clients · Never send it to Spam
  4. Calendar invitations

    Meeting invitations carry an .ics calendar file. Labeling them keeps invites, updates and cancellations together.

    Search
    filename:ics
    Then
    Apply the label: Calendar
  5. Large attachments

    Labels big files as they arrive, so you know what to clear when storage runs low. Gmail attachments count toward your Google account storage.

    Search
    has:attachment larger:10M
    Then
    Apply the label: Large files
  6. Social network notifications

    Sends likes, invitations and alerts to the Social tab instead of Primary. Add any other network that emails you.

    Search
    from:(facebookmail.com OR linkedin.com OR x.com OR instagram.com)
    Then
    Categorize as: Social
  7. Your boss or most important people

    Makes sure mail from one person is never caught by spam filtering, is starred and is marked important. Add more people with commas.

    Search
    from:boss@example.com
    Then
    Star it · Never send it to Spam · Always mark it as important
  8. Old promotions cleanup

    A one-time cleanup. Filters check mail as it arrives, and new mail is never 30 days old, so this only works on mail you already have: tick Also apply filter to matching conversations, or search and delete by hand.

    Search
    category:promotions older_than:30d
    Then
    Delete it
  9. Automated no-reply senders

    Labels mail from addresses you can't reply to. Don't make it skip the inbox: sign-in codes and password resets come from no-reply addresses too.

    Search
    from:(noreply OR "no-reply" OR donotreply OR "do-not-reply")
    Then
    Apply the label: Automated
  10. Unknown senders

    Gmail has no "not in my contacts" condition, so this is an allow list you type by hand: mail to you from anyone not on the list skips the inbox. You have to add every new contact yourself.

    Search
    to:me -from:(@yourcompany.com OR friend@example.org)
    Then
    Skip the Inbox (Archive it) · Apply the label: To screen

Filters and rules in each email app

App Called Where to find it Where it runs
Gmail Filter Search options, then Create filter Google's servers, so every device
Outlook on the web, new Outlook Rule Settings, Mail, Rules Microsoft's servers for Microsoft accounts
Classic Outlook for Windows Rule Home, Rules, Manage Rules & Alerts The server, or this PC for client-only rules
Apple Mail on a Mac Rule Mail, Settings, Rules This Mac, while Mail is open
iCloud Mail Rule Settings, Rules on iCloud.com Apple's servers, up to 500 rules
Yahoo Mail Filter Settings, More Settings, Filters Yahoo's servers, up to 500 filters

Where native filters stop

Filters need to know the sender in advance

Every filter above works from something you already know: an address, a domain, a word in the subject. That handles newsletters, receipts and notifications well. It can't handle the mail that causes most of the noise: people you have never heard from, such as cold sales pitches, recruiters and scams. Gmail, Outlook and Yahoo have no condition for "the sender isn't in my contacts".

You can build an allow list by hand, like the unknown senders example above, but you have to add every new contact yourself, and long lists get hard to maintain. The guide to blocking emails from unknown senders in Gmail compares that with the other options.

KeepKnown adds that missing rule for Gmail and Outlook. It checks each new sender against your contacts and the domains you approve, and moves unknown senders to a KK:OUTSIDERS label instead of deleting them. You can describe other rules in plain English too, and preview which messages a rule would move before anything moves. Other screening tools take different approaches; the SaneBox alternatives comparison covers them.

The audit is free and changes nothing in your inbox. See how contacts-only Gmail works.

Frequently asked questions

How many filters can I create in Gmail?

Google doesn't publish a total limit for personal Gmail accounts, and most people never reach one. For Google Workspace accounts, Google documents a limit of 40 filters that automatically forward mail. Very long filters can fail to save, so split a long list of senders across two or more filters.

Why is my Gmail filter not working?

Run the filter's criteria as a search first. If the search doesn't find the message, the filter won't either, so check the spelling, the exact address and that OR is written in capitals. A filter only acts on mail that arrives after you create it, unless you tick Also apply filter to matching conversations. Every filter that matches a message applies, so look for a second filter that archives or deletes the same mail.

How do I filter emails from several senders at once?

Put the addresses in the From field separated by OR, such as a@example.com OR b@example.com, or wrap them in curly braces: {a@example.com b@example.com}. To cover a whole company, use its domain, such as @example.com. The filter creator on this page accepts a comma-separated list and adds the ORs for you.

Does deleting a filter bring back the emails it moved?

No. Deleting a filter only stops it acting on new mail. Messages it already archived, labeled or deleted stay where they are. Search for the label, or look in Trash, where Gmail keeps deleted mail for 30 days, and move them back yourself.

Can I create a Gmail filter on my phone?

Not in the Gmail app for iPhone or Android. Open mail.google.com in your phone's browser, switch to the desktop site, and create the filter there. It then runs on every device, including the app, because Gmail applies filters on Google's servers.

Do email filters work on emails I already have?

Only if you ask. In Gmail, tick Also apply filter to matching conversations when you create or edit the filter. In new Outlook, run the rule from Settings > Mail > Rules. In Apple Mail, select the messages and choose Message > Apply Rules. Forwarding never applies to old mail.

Can a filter block everyone who isn't in my contacts?

Not in Gmail or Yahoo Mail: neither has a condition for senders who aren't in your contacts. You can list the senders you allow and archive everyone else, but you have to keep that list up to date by hand. KeepKnown adds the missing condition for Gmail and Outlook and moves unknown senders to a label instead of deleting them.

Related guides

Sources: Gmail Help, create rules to filter your emails; Microsoft Support, rules in Outlook; iCloud User Guide, filtering rules; Yahoo Help, filters.

Beyond Gmail filters

Filters need a sender you know. KeepKnown screens the ones you don't.