Free tool
Gmail filter generator
Pick what a message should match and what Gmail should do with it. You get the search query to paste into Gmail, and a filter file you can import.
Runs in your browser. Nothing you enter is sent to InboxNight.
- Choose at least one action to get a filter file. The search query above works without one.
Gmail search query
Fill in a criterion to see the query.
How to use it
- Fill in at least one field: sender, recipient, subject, words to include or leave out, a size, or has attachment.
- Tick the actions you want, such as skip the inbox, mark as read, star it or apply a label. The query works without any action.
- Test the match first: copy the search query and paste it into the Gmail search box. The results are what the filter would catch.
- To create the filter by hand, open the search options menu in the Gmail search box, paste the query into "Has the words", choose "Create filter" and pick your actions.
- To import instead, download the filter file. In Gmail open Settings, See all settings, then Filters and Blocked Addresses, choose Import filters, select the file and create the filters. Menu names are as Gmail shows them today and may change.
How the query is built
The tool follows fixed rules. Each field you fill in becomes one part of the query, and the parts are joined with spaces in the same order every time.
- From and To accept several addresses separated by commas, semicolons or spaces. They are joined with OR, and quotes and brackets are removed from addresses.
- A Subject with more than one word is wrapped in brackets, so from:news@example.com subject:(weekly report) keeps the words together.
- Has the words is added as typed. When it holds more than one word it is wrapped in brackets so the words stay together.
- Does not have becomes a minus sign and braces, which excludes a message that contains any one of the listed words.
- Size becomes larger: or smaller: followed by the amount and M for MB, K for KB, or nothing for bytes.
- Has an attachment adds has:attachment at the end of the query.
What code decides
Nothing here is guessed. Code applies the same steps to every entry.
- Runs of spaces collapse to one, and the text is trimmed before it is used.
- Gmail search has no escape character, so an unmatched quote, round bracket or curly bracket is removed and a note says so. A matched pair is kept.
- Size must be a whole number above zero. Anything else shows an error and no query.
- The filter file is made only when there is at least one criterion, no error and at least one action. Names and values are escaped before they go into the file.
- A label is trimmed and has its spaces collapsed. A slash makes a nested label such as Clients/Active.
What this tool does not do
- It never connects to your Gmail account and never creates a filter for you.
- It cannot tell you how many messages a query will catch. Paste the query into the Gmail search box to see.
- It does not search by a sender display name. From matches an address or a domain.
- It uses no regular expressions and no wildcards, because Gmail search does not read them.
- It does not read a sentence. Each value goes into its own field.
Worked examples
Receipts with attachments
You enter: From invoices@brightmill.example, has the words receipt, has an attachment, apply the label Receipts.
You get: Query: from:invoices@brightmill.example receipt has:attachment. The filter file applies the label Receipts.
A digest you read later
You enter: From news@quillandco.example, subject weekly digest, tick skip the inbox and mark as read.
You get: Query: from:news@quillandco.example subject:(weekly digest). The filter file archives the message and marks it read.
Large files, no action yet
You enter: Size larger than 10 MB, no action chosen.
You get: Query: larger:10M. No file is made yet, and a note asks you to choose at least one action to get one.
Common mistakes
- Skipping the test in Gmail search. Paste the query into the Gmail search box first. The results are exactly what the filter would act on.
- Searching a person by display name. From matches an address or a domain. Use the address, or a domain such as example.com, when you have it.
- Expecting a filter to reach mail already in the inbox. A filter acts on mail as it arrives. To apply one to mail already there, choose the option that applies it to matching conversations when you create it.
- Leaving a quote or bracket open. Gmail search has no escape character. An unmatched quote or bracket changes what the query means, so the tool removes it and says so.
Questions and answers
Can I import what the tool makes?
Yes. Download the filter file and use Import filters in the Gmail settings. The file holds one filter with the criteria and actions you chose.
Which fields can it use?
Sender, recipient, subject, words to include, words to leave out, size and has attachment, with the actions skip the inbox, mark as read, star, never send to spam and a label.
Why does Does not have exclude a message with any one of the words?
The tool writes those words inside braces after a minus sign, and Gmail reads that as: leave out a message that has any one of them.
Why was a quote removed from my text?
Gmail search has no escape character, so a quote without a partner would change the meaning of the whole query. The tool removes it and shows a note.
Does a filter catch mail that is already in my inbox?
Not unless you choose the option to apply it to matching conversations when you create or import it. Filters act on new mail as it arrives.
Is anything I type stored or sent?
No. The form runs in your browser and nothing you enter is sent to InboxNight.