Skip to content
// generated · Gmail

Label a Gmail conversation when a priority sender replies.

When mail from a specific person lands, I want it flagged so it never gets lost in the pile.

“Automatically label every email from my manager as "Priority" and star it.”

Which reply gets the Priority label?

A vendor and two colleagues share a support conversation. Compare a sender filter active from the start with one run of the script below at 09:10. Both actions apply the Priority label and a star. This local replay uses fictional messages.

Sender filter: 1 of 3. Script at 09:10: 3 of 3.

MessageSender filterScript at 09:10
09:00 · Nora · support
Can the replacement part leave today?
UnmarkedLabel + star
09:03 · Rita · vendor
Yes. It is packed at our depot.
Label + starLabel + star
09:05 · Emil · dispatch
I have booked the pickup.
UnmarkedLabel + star

To flag only incoming messages from the sender, use Gmail’s search options, fill in From, then choose Create filter, Apply the label and Star it. For a whole conversation, the script below labels the existing thread and stars each message in it at the time of the run. Gmail filter instructions

The script

copy · paste · trigger
labelPriorityFromBoss.gs
Apps Script
// Made with bulldo.gs · describe an automation, get working Apps Script.
// Fork or fix this one → https://bulldo.gs/g/label-priority-from-boss

// Label matching threads and star every existing message. Use a time trigger
// (every 5-15 minutes) to look for recent mail from the sender.
const BOSS = 'manager@example.com';

function labelPriorityFromBoss() {
  const label = GmailApp.getUserLabelByName('Priority') || GmailApp.createLabel('Priority');
  const threads = GmailApp.search('from:' + BOSS + ' newer_than:1d -label:Priority', 0, 50);
  threads.forEach(function (t) {
    t.addLabel(label);
    t.getMessages().forEach(function (m) { m.star(); });
  });
}
Fork this script

Made with bulldo.gs. Fork it to change a field, a trigger, or the edge cases — describe the change and Gnaw rewrites it.

Walkthrough

How it works

The script looks up the Priority label and creates it if it is missing.

The query looks for recent messages from the selected sender without the Priority label and returns up to 50 matching conversations.

For each returned thread, the script adds the label and stars every message already in the conversation, including earlier messages from other people.

Set the sender + trigger

Replace manager@example.com with the address you care about. Then add a time-based trigger (Triggers → minutes timer → every 5–15 minutes). Review the Gmail access requested by Apps Script before authorizing it.

Need a different version?

Describe your sheet or inbox and the rule you want. Gnaw writes the Apps Script — fields, triggers, edge cases — in one shot.

FAQ

3 questions
Can I watch more than one sender?
Yes — change the query to `from:([email protected] OR [email protected])`. The rest of the script is unchanged.
Why `newer_than:1d` instead of every email ever?
It bounds each run to recent mail so you do not re-scan your whole mailbox every few minutes. A first-time backfill can be run once with a wider window.
Will it re-star threads I already handled?
A later matching message can bring the conversation back into the search. If it does, the script stars every message present again, including a message you previously unstarred.