Create Gmail Filter if Message Body Contains Your Name

gmailgmail-filters

I have a couple on-going conversation threads in Gmail with a number of different people. Is there a way to setup a filter so that it will add a label if the body of any new, unread email contains my name? Then remove the label once I've read the email?

Best Answer

Remember that you can use any Gmail search operator in a filter via the Has the words: textbox since Gmail just AND's together the operators that are filled in via the filter dialog.

I'll suggest you start by trying this:

  1. Create a filter that finds new emails with your name in them and applies a temporary label. The search operation you would use in the filter is:

    is:unread AND body:"Your Name"
    
  2. Create a filter that finds read emails in the temporary label and removes the label.

    label:templabel AND is:read
    

    Unfortunately, while filters can operate on read emails, they cannot currently remove labels, we are at a stopping point.

-

Sorry can't help more, but until Gmail filters can remove a label, you will not be able to accomplish this via filters.

Potential workarounds would be:

  1. Setup an IMAP client with the equivalent filtering where instead of adding/removing a temporary label you would be copying/deleting the email from the temporary folder.

  2. Google recently introduced a new scripting framework for Google Apps.

  3. One really crude hack for step 2 would be to have the filter forward the email as well as delete it. You would forward to your own email address with a plus extension, e.g. username+templabelname@gmail.com.

    Then a new step 3 would be to catch those emails using the deliveredto:username+templabel@gmail.com search string, and reapply some label.

    Not sure how cleanly this method would work, especially because you would get header cruft from the forward (vs. redirecting).

Personally, I would look at #2 since learning scripting for Google Apps would pay off in the long run.