Archive newsletters automatically after seven days
Sweep read promotional mail on a daily schedule to keep the inbox clean.
Published Sep 23, 2025
The Northwind inbox fills with newsletters Awadesh reads once and forgets. They are not spam — they are worth a glance — but a week later they are just clutter sitting in the inbox, pushing real work out of view. Archiving them by hand is the kind of chore nobody keeps up.
This script does the sweep on a schedule. Once a day it finds promotional mail that has already been read and is more than seven days old, and archives it. The newsletters stay searchable in All Mail; they just stop crowding the inbox. Anything unread, or newer than a week, is left exactly where it is.
What you’ll need
- A Gmail account where newsletters land in the Promotions category — the default for most marketing mail.
- Nothing else to set up. The search itself decides what gets swept, so there is no sheet or label to prepare.
The script
// Gmail search that selects what to sweep: promotional mail in the
// inbox, already read, and older than seven days.
const SWEEP_QUERY = 'in:inbox category:promotions is:read older_than:7d';
/**
* Finds read promotional mail older than seven days and archives it,
* clearing newsletters out of the inbox while leaving them searchable.
*/
function archiveOldNewsletters() {
// 1. Find every thread matching the sweep query.
const threads = GmailApp.search(SWEEP_QUERY);
// 2. Nothing matched — stop quietly.
if (!threads.length) {
console.log('No newsletters to archive.');
return;
}
// 3. Archive each matching thread out of the inbox.
threads.forEach((t) => t.moveToArchive());
console.log(`Archived ${threads.length}`);
}
How it works
archiveOldNewslettersruns theSWEEP_QUERYGmail search. The query has four parts:in:inbox(still in the inbox),category:promotions(Gmail’s marketing category),is:read(already opened), andolder_than:7d(more than a week old).- If nothing matched, it logs that and stops.
- Otherwise it calls
moveToArchiveon each matching thread, which removes it from the inbox but keeps it in All Mail, fully searchable.
Example run
Say the inbox holds these promotional threads when the script runs on 25 May:
| Newsletter | Read? | Age | Result |
|---|---|---|---|
| Design Weekly | read | 9 days | archived |
| Tooling Digest | read | 3 days | kept (too new) |
| Conference invite | unread | 12 days | kept (unread) |
| Studio News | read | 8 days | archived |
The log reads Archived 2. The inbox loses the two stale, already-read
newsletters; the unread one and the recent one stay put.
Trigger it
Run this on a daily timer so the inbox is swept every morning:
- In the Apps Script editor open Triggers and click Add Trigger.
- Choose
archiveOldNewsletters, set the event source to Time-driven, and pick a Day timer for the 6am to 7am slot.
Once a day is plenty — the seven-day window means there is no rush to catch mail the moment it ages out.
Watch out for
- It relies on Gmail’s
category:promotionsbeing accurate. If a newsletter is misfiled into Primary it is never swept. To be sure, tag newsletters with a Gmail filter and searchlabel:newslettersinstead of the category. - Only read mail is touched —
is:readprotects anything you have not opened yet, even if it is months old. moveToArchiveonly archives; it never deletes. Swept newsletters stay in All Mail and still surface in search.- To spare a particular sender, add an exclusion to the query, for example
-from:[email protected]. GmailApp.searchreturns at most 500 threads per call. A normal daily sweep is well under that, but a first run on a long-neglected inbox might need to be run a few times to clear the backlog.
Related
Convert long email threads into a summary note
Collapse a thread's history into a Doc for handover — perfect for client transitions or vacation cover.
Updated Jun 6, 2026
Pull event RSVPs from emails into a Sheet
Parse yes/no replies to event invites and tally attendance automatically.
Updated Jun 2, 2026
Turn forwarded emails into project tasks
Forward to [email protected] and a row lands in the Projects sheet under the right client.
Updated May 30, 2026
Turn starred emails into a task list
Sync every starred thread into the Northwind Tasks sheet automatically.
Updated May 26, 2026
Alert when a label hits a backlog threshold
Warn the Northwind team in Slack when a Gmail label has more than N unread threads.
Updated Mar 31, 2026