145

How can I filter messages in Gmail using boolean OR conditions? For example, I can specify addresses in the To: or From: fields, but this only matches emails that meet both criteria. How can I match emails that meet one or both criteria?

127

Type into the search field of Gmail:

from:xyz OR to:uvw

see also here.

to make a filter (and apply actions to that filter) from that search: click the little down arrow on the right side of the search field and then click create filter with this search.

  • 3
    Thanks. You've saved me a lot of frustration. I have a friend who doesn't know about the BCC field and likes to email TONS of people who like to reply-to-all. – jessegavin Jul 19 '10 at 17:49
  • 1
    At first I thought this answer is correct, but now I see that OP asked about filtering, and you said "type into the search field." Now my vote goes to Senseful. Good, succinct answer, though! – Limited Atonement Jul 1 '13 at 16:05
  • 1
    @akira The OP asked about filtering email messages (which I read to mean applying inbound filters), and your answer is about searching for email messages. – Limited Atonement Jul 2 '13 at 14:26
  • 1
    @LimitedAtonement: so, all you need to be happy is a "after the search click 'create filter'" statement somewhere? – akira Jul 2 '13 at 15:22
  • 5
    To clarify for anyone who might run into this: "OR" is case sensitive (i.e. "or" won't work). – kevinmicke Feb 21 '17 at 22:58
52

If you are talking about searching, then @akira's question is correct. However, it sounds like you are asking about how to use this condition in a filter.

The trick is that you can put whatever search criteria you want in the filter's Has the words field. For any other field it will prefix your criteria with the field name. For example, if you type user@example.com in the To field, it'll create the filter condition to:(user@example.com). The reason it works in the Has the words field, is because it doesn't prefix it with anything. This is because it acts as a normal search on the content of the email.

  1. Create or modify a filter.
  2. In the Has the words field, enter your OR condition. For example: to:user@example.com OR from:user@example.com

This is also the place to put any other attributes you want to match (e.g. label:, in:, etc.).

This will also work in the Show search options page, however it's easier to just use a normal search instead.

  • 4
    This should be the accepted answer. Using the workflow in akira's answer does not work, because the search criteria get mangled as soon as you click on "create filter with this search". Advanced boolean expressions are left untouched only when using the "Has the words" field, like suggested in this answer. – Marco Leogrande Sep 23 '16 at 22:37
36

To my surprise, the solution to me was using the vertical bar | between emails instead of the comma , in the TO filed during filter creation.

Example:

name1@domain.com | name2@domain.com | name3@domain.com`

The search box would look like:

to:(name1@domain.com | name2@domain.com | name3@domain.com)

I got a popup message from Gmail saying that using special characters may give unexpected results. Just clicked on continue and it worked perfectly.

15

Gmail accepts several syntaxes:

apple OR orange apple | orange {apple orange}

Personally, I like to use the curly braces because it is nice and concise. The following are all equivalent:

from:{john jane joe} {from:john from:jane from:joe} (from:john OR from:jane OR from:joe)

7

You can group them:

{"Words1" AND "Words2"} OR {"Words1" AND "Words3"} etc...

1

Either A OR B and A | B work for me.

New contributor
Mawanda Almuhayar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

The best way I've got to work for the to field is:

to:({first@email.com second@email.com third@email.com})
0

You need to use has the words input field instead. This will let you update existing filters instead of deleting and creating new ones.

Example: from:(sas.com) OR to:(sas.com)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.