# Gmail filter generator

> Create Gmail filters for many senders, domains and subjects, test each one in Gmail search, then import them all as one mailFilters.xml. Free, no sign-in.

Type senders or paste a Gmail search, then say what Gmail should do with the mail. Each filter gets a search to test it in Gmail, and all of them go in one mailFilters.xml that Gmail imports. Open a file you exported from Gmail to change it. The tool runs on its page, https://construct.computer/tools/gmail-filter-generator/.

## Gmail search operators

| Operator | What it finds | Example | In a filter |
| --- | --- | --- | --- |
| from: | The sender, by address or domain | from:@acme.com | Yes |
| to: | A recipient | to:you+receipts@gmail.com | Yes |
| cc: and bcc: | Someone copied in | cc:team@acme.com | Yes |
| deliveredto: | The address it was delivered to | deliveredto:you+news@gmail.com | Yes |
| subject: | Words in the subject line | subject:invoice | Yes |
| OR, or { } | Either term, with OR in capitals | from:(amy@acme.com OR dan@acme.com) | Yes |
| Minus (-) | Leaves out mail with the word | invoice -paid | Yes |
| " " | An exact phrase | "order confirmation" | Yes |
| ( ) | Groups terms | subject:(receipt OR invoice) | Yes |
| has:attachment | Mail with any attachment | has:attachment from:@bank.com | Yes |
| filename: | An attachment's name or type | filename:pdf | Yes |
| larger: and smaller: | Size, with M for megabytes | larger:10M | Yes |
| list: | Mail from a mailing list | list:news@acme.com | Yes |
| label:, in: and is: | Where mail sits or what's been done to it | is:unread | Search only |
| older_than: and newer_than: | Age, in d, m or y | older_than:1y | Search only |

From Google's [list of Gmail search operators](https://support.google.com/mail/answer/7190), checked on 14 November 2026. A filter acts on mail as it arrives, so an operator about where mail sits, what's been done to it or how old it is only helps in search.

## The mailFilters.xml format

| What it does | In Gmail's filter form | In the file |
| --- | --- | --- |
| Matches the sender | From | from |
| Matches a recipient | To | to |
| Matches the subject | Subject | subject |
| Matches words, phrases and operators | Has the words | hasTheWord |
| Leaves out words | Doesn't have | doesNotHaveTheWord |
| Needs an attachment | Has attachment | hasAttachment |
| Matches size | Size, greater or less than | size, sizeOperator (s_sl or s_ss) and sizeUnit (s_smb, s_skb or s_sb) |
| Skips the inbox | Skip the Inbox (Archive it) | shouldArchive |
| Marks it read | Mark as read | shouldMarkAsRead |
| Stars it | Star it | shouldStar |
| Labels it | Apply the label | label, with a slash for a nested label |
| Forwards it | Forward it to | forwardTo |
| Deletes it | Delete it | shouldTrash |
| Keeps it out of spam | Never send it to Spam | shouldNeverSpam |
| Sets importance | Always, or Never, mark it as important | shouldAlwaysMarkAsImportant or shouldNeverMarkAsImportant |
| Moves it to a tab | Categorize as | smartLabelToApply: ^smartlabel_personal, social, promo, notification, group or receipt |

Google doesn't publish the format. These are the names Gmail writes when it exports filters, which open-source tools like [gmailctl](https://github.com/mbrt/gmailctl) use too. Purchases, as ^smartlabel_receipt, is the newest, added to gmailctl in May 2026.

## Make filters from an agent or a script

Fetch this page with a filter's words, like from=, subject=, has=, label= and archive=1, and it answers in Markdown: each filter in words with its Gmail search, the file, and how to import it. Number the words for more than one filter, like 1.from= and 2.from=. Add &format=json for JSON, or &format=xml for mailFilters.xml itself, which a browser downloads. In a browser with WebMCP, the page offers the same as its make_gmail_filters tool.

```
https://construct.computer/tools/gmail-filter-generator/?from=@acme.com&label=Clients&archive=1
```

## Questions

### How do I create a filter in Gmail?

On a computer, click Show search options at the right of Gmail's search box, fill in who the mail is from or what it says, then click Create filter, tick what Gmail should do and click Create filter again. To make several at once, write them here and import the file. [Google's steps](https://support.google.com/mail/answer/6579).

### How do I import filters into Gmail?

Open Gmail on a computer, click the gear and choose See all settings. On Filters and Blocked Addresses, click Import filters at the bottom, choose mailFilters.xml and click Open file. Gmail lists the filters it found: tick Apply new filters to existing email to sort mail that's already there, then click Create filters. [Google's steps](https://support.google.com/mail/answer/6579).

### How do I export my Gmail filters?

In Gmail's settings, on Filters and Blocked Addresses, tick the filters you want, or Select all, and click Export. Gmail saves them as mailFilters.xml. Open that file here to read every filter in plain words, change them and make a new file to import.

### How do I filter mail from several senders or a whole domain?

Type the addresses in From with commas between them, and the generator joins them with OR, the way Gmail needs: from:(amy@acme.com OR dan@acme.com). Gmail also reads {amy@acme.com dan@acme.com} as either one. For everyone at a company, type the domain on its own, like @acme.com. Gmail has no wildcard like *, and the domain does the same job.

### Will a new filter sort the mail I already have?

Only if you ask it to, since a filter acts on mail as it arrives. When you import the file, tick Apply new filters to existing email. For a filter already in Gmail, click edit, then Continue, tick Also apply filter to matching conversations and click Update filter. Gmail skips mail in Spam and Trash, and forwarding only ever acts on new mail.

### How do I automatically delete emails in Gmail?

Make a filter that matches them and ticks Delete it. New mail that matches goes straight to Trash, which Gmail empties after 30 days, and Apply to existing email clears what's already there once. A filter can't delete mail as it gets old, since older_than: only works in search: search for older_than:1y and delete the results by hand.

### Why isn't my Gmail filter working?

Most often it's one of four things. A filter acts only on mail that arrives after you make it. Operators about where mail sits or its age, like label:, is: and older_than:, never match arriving mail. Mail in Spam and Trash is skipped. And forwarding needs an address you've verified. Click Search Gmail under a filter here to see what it catches before you import it.

### How many filters can Gmail have?

Up to 1,000 filters an account, as Google's Gmail API puts it. A filter with many senders joined by OR counts as one, so group senders that get the same treatment. [Google on filter limits](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings.filters/create).

### Can a Gmail filter forward emails?

Yes, to an address you've added and verified first, in Settings, Forwarding and POP/IMAP, Add a forwarding address. Add it there before you import a filter that forwards, and expect it to act on new mail only. [Google on forwarding](https://support.google.com/mail/answer/10957).

### Are Gmail filters the same as rules?

Yes. Gmail calls them filters, and Google's help calls them rules to filter your emails, the word Outlook uses. Each one is a search that Gmail runs on every new email, with what to do when it matches.

### Can I make Gmail filters on my phone?

Not in the Gmail app, which can't create, edit or import filters. You can build the file on your phone here, then import it from Gmail in a browser on a computer.

### Can a filter tell an urgent email from one that can wait?

No. A filter checks the sender, the subject, the words and a few facts like size and attachments, so a client asking for a quote and a sales pitch with the same words land in the same place. Telling them apart takes something that reads each email.

### Is anything I type kept?

Not from this page. The filters and the file are made in your browser, and a file you open is read there too. Your filters' words go in this page's address as you make them, so a copied address shows the same filters in any app it's shared to. Opening that address, or an agent's GET with a filter's words, carries them in the address, which our request logs keep for up to 7 days.

Filters go by words, so a client's question and a cold pitch that share them land in one label. In Construct, the Inbox Manager reads each new email, sorts it by what it needs from you and drafts the replies for you to check. [Try it in Construct](https://construct.computer/?prompt=Sort%20my%20Gmail%20inbox%20every%20morning%3A%20label%20each%20new%20email%20Reply%20needed%2C%20FYI%20or%20Receipts%2C%20and%20draft%20replies%20to%20the%20ones%20that%20need%20me.).

---

The Markdown copy of https://construct.computer/tools/gmail-filter-generator/. Everything Construct Computer publishes is listed in https://construct.computer/llms.txt.
