You can use Filters to configure advanced filtering rules for an account. Filters can automatically add or remove labels or forward emails to verified aliases based on the attributes or content of the incoming message.
For information on how to create, list, get, or delete filters, see the Filters reference.
Matching criteria
You can filter messages by properties such as the sender, subject date, size, and message contents. Any query using Gmail's advanced search syntax can also be used in a filter. For example, common filter patterns include:
Filter | Matches |
---|---|
criteria.from='sender@example.com' |
All emails from sender@example.com |
criteria.size=10485760 criteria.sizeComparison='larger' |
All emails larger than 10MB |
criteria.hasAttachment=true |
All emails with an attachment |
criteria.subject='[People with Pets]' |
All emails with the string [People with Pets] in the subject |
criteria.query='"my important project"' |
All emails containing the string my important project |
criteria.negatedQuery='"secret knock"' |
All emails that do not contain the string secret knock |
If multiple criteria are present in a filter, a message must satisfy all criteria for the filter to apply.
Actions
You can apply an action to messages matching the filter criteria. Messages may be forwarded to a verified email address, or have labels added or removed.
You can add or remove labels to change the disposition of the email. For example, some common actions include:
Action | Effect |
---|---|
action.removeLabelIds=['INBOX'] |
Archive the email (skip the inbox) |
action.removeLabelIds=['UNREAD'] |
Mark as read |
action.removeLabelIds=['SPAM'] |
Never mark as spam |
action.removeLabelIds=['IMPORTANT'] |
Never mark as important |
action.addLabelIds=['IMPORTANT'] |
Mark as important |
action.addLabelIds=['TRASH'] |
Delete the email |
action.addLabelIds=['STARRED'] |
Mark as starred |
action.addLabelIds=['<user label id>'] |
Tag the mail with a user-defined label. Only one user-defined label is allowed per filter. |
Examples
The following is a more complete example showing how to label and archive messages from a mailing list.