Google Apps Script that labels recent unlabeled Gmail threads:
- Contact Exists — sender email is in your Google Contacts and not in the Ignore contact group
- Not in Contacts — sender is unknown, or is in Ignore
Uses the People API (not the deprecated ContactsApp).
| File | Role |
|---|---|
Code.gs |
Script source |
appsscript.json |
Manifest (People advanced service + OAuth scopes) |
- Searches
newer_than:10d has:nouserlabels - Builds a contact email index once per run (paginated Connections + ContactGroups)
- Labels each matching thread once
- Go to script.google.com → New project
- Copy
Code.gsfrom this repo into the editor (replace the defaultCode.gs) - Project Settings → show
appsscript.json, then replace it with the repo’sappsscript.json - Confirm People API is enabled under Services / Advanced Google services (the manifest already declares it)
- Run
addLabelIfContactExistsonce and approve Gmail + Contacts when prompted - Triggers → add a time-driven trigger on
addLabelIfContactExists(e.g. every 5–15 minutes)
If you previously pasted the old README script that used ContactsApp, replace both Code.gs and appsscript.json with the current files on main, then run the function once to re-authorize.
Create a Google Contacts group named Ignore. Contacts in that group are labeled Not in Contacts.
- Labels are created automatically if missing.
- Only personal Google Contacts are checked (not the Workspace domain directory).
- Search window defaults to the last 10 days of unlabeled mail; change
newer_than:10dinprocessEmails()if you want a different window.
MIT