Thursday, March 24, 2022

Gmail manual spam filtering using keywords

While Gmail comes built-in with pretty good spam filtering, there are many people out there spending major resources on trying to circumvent those, and so anyone who uses email will inevitably end up receiving a certain amount of spam, no matter what they do. For some, you can unsubscribe using the advertiser's own button, and for others, you might be able to gain some quiet by using Gmail's own "report spam" button, but these too don't always work as there are quite a few very effective and persistent spammers out there. The good news, though, is that Gmail does have a function to create your own custom filters, which can allow you to get rid of spam using keywords you define on your own. Here's how to use this feature. 

Step 1: do the math. 

To be able to filter the spam, you need to figure out a pattern that you can set your filters to. That pattern can be a keyword or two in the subject or body, for example, or a specific sender. This is the hard part, as it will require you to out-smart the spammers to some level. They do use various mechanisms to escape the filtering, such as changing their email or name (sometimes several times per day), or replacing characters in words (like using "S@le" instead of "Sale" or "Win ner" instead of "Winner"), so be prepared for this to require some thought, and likely some trial-and-error and time until you catch all, or at least most of them. For example, a filter you might come up with could be "messages with the words 'custom watches' or 'quick sale' in the subject". Keep in mind that targeting a single keyword is risky, because that risks missing emails that you DO want, so it's important to test out your filter carefully before using it.


Step 2: Write the filter.

To be effective, you'd typically want to create few or one filter rule, rather than a dozen, so grouping keywords together is important. For this, Gmail uses the pipe symbol. Also, to use a keyword set with a space in it, you need to enclose it in quotes, otherwise Gmail will look for EACH word separately. To filter for words in the subject, use the keyword "subject:" and to search in the body, use "body:", so a search filter might look like this:

subject:("pretty jewlery"|"one time sale"|"buy now")

or:

body:("waiting for your reply"|"don't wait"|"urgent matter"|"hurry up")

There are other things you can filter by, though those might not be useful for spam specifically. Adding them here just for informational purposes:

Size, by adding "size:5mb" to filter for emails larger than 5mb. 

From or to, by adding that keyword, like "from:john@watches.com"

Negative keywords: adding a minus sign, like "-erez" will exclude emails which have that word from the filter

Has attachments, by adding "has:attachment"


Step 3: Test the filter

To test your filter, paste it into the Search box on the Gmail inbox, and see what it produces. If you already have some spam in there, this is how you see if it catches it or not, as well as if it catches "good" email you don't want to filter. If it did, it will show you in yellow what keywords caught that email specifically, so you can use that to refine the filter. Ultimately, this is a bit of a give-and-take. The tighter the filter, the more likely it will catch some emails you do want (a.k.a. False Positives). You might be willing to live with that, or prefer to loosen up the filter and deal with some spam that will escape it.


Step 4: Apply the filter

Use Gmail's Settings and go to the "Filters and blocked addresses" tab. In there, create a new filter and paste in the filter you came up with, and then use "continue" to choose what to do with these. You can delete them, or just archive them (which is safer, as it would still allow you to search for them later, if you suspect you may have missed an important email).

Good luck with your spam-catching!