Previous Section  < Day Day Up >  Next Section

6.2. Gmail Search Syntax

Gmail offers a rich search syntax for routing through your email message archive—as if you'd expect, or indeed stand for, any less.


Digs through the headers of your email message archive in search of mail sent by someone matching the keyword that you provide.


The yang to from:'s yin, to: finds all messages sent to someone matching a provided keyword. (Don't forget plus-addressing Hack #72.)


Matches messages with a particular subject.

subject:"meeting notes"


Looks for messages with a particular label applied.



The has: syntax has only one possible value (at least at the time of this writing): attachment. has:attachment in a query returns only messages having one or more attachments.



Finds messages with an attachment filename matching a provided pattern. Used with just a file extension (e.g., pdf or txt), filename: turns up all messages with attachments of a particular type.




Returns a list of messages in a particular collection (read: folder). Acceptable values for in: are inbox, trash, spam, and anywhere (trash and spam are not included in searches unless explicitly included using in:trash, in:spam, or in:anywhere). Oddly enough, sent isn't a usable value for in:.




Acceptable values for is: are starred, unread, and read, which return starred, unread, and read messages, respectively.



Finds messages carbon copied to particular recipients.


Finds outgoing messages blind carbon copied to particular recipients. Note that bcc: won't work on any incoming mail since there's no way to tell who was on the bcc line.


Matches messages sent or received before a particular date, specified in yyyy/mm/dd format. Unfortunately, partial dates—year only or year and month—don't find anything at all.



Match messages sent or received on or after a particular date, specified in yyyy/mm/dd format.


6.2.1. Phrase Searches

Enclose phrases in double-quotes (") to have Gmail search treat them as a unit to be matched exactly (case isn't taken into account). The following query finds only accounting department reports:

Subject:"accounting department report"

6.2.2. Basic Boolean

The only Boolean operator supported by Gmail search is OR (uppercase is required). In the absence of the OR operator, AND is implicit.

The Boolean OR operator works in Gmail searches just as it does in Google Web searches: specify that any one word or phrase is acceptable by putting an OR between each, such as this query, which finds all messages from the boss or with their subjects marked as urgent: OR subject:urgent

6.2.3. Negation

The negation operator (-) also works as it does in Google Web Search, excluding messages matching the negated keyword or operator:keyword pair. So, the following query turns up all messages to my Example Co. not sent from the company's special offers department:

to:@examplecom -from:offers@

6.2.4. Grouping

Parentheses are used a little strangely in Gmail queries. When enclosing a set of words, they specify that all of those words must be found to be considered a match. So, the following matches messages sent to both Sam and Mira:

to:(sam mira)

Throwing in an OR allows optional matches while being explicit about groups of options—while we humans tend to be able to parse precedence without need of parentheses, search engines need a little more help. The following query finds all messages sent to Sam about rockets or helicopters:

to:sam subject:(rockets OR helicopters)

6.2.5. Mixing Syntax

Gmail's various search operators tend to play well together. While the tendency is to start out with minimal search criteria and keep whittling down, with a large number of email messages, crafting your searches can start to take a lot of work. Take a chance and provide as much information as you know about the message you're after and back off bit by bit if you don't find it. The following query, for instance, is one that I just couldn't pull off in my computer's email client:

from:Duncan before:2004/10/01 subject:today "World Cup" lunch

    Previous Section  < Day Day Up >  Next Section