Skip to content

Instantly share code, notes, and snippets.

@chasecmiller
Created October 26, 2025 17:30
Show Gist options
  • Select an option

  • Save chasecmiller/c0a139066a5102305717b5503d447957 to your computer and use it in GitHub Desktop.

Select an option

Save chasecmiller/c0a139066a5102305717b5503d447957 to your computer and use it in GitHub Desktop.
Google Script to help filter political emails to spam.
function filterPoliticalEmailsByDomain() {
// List of political domains
const politicalDomains = [
'ngpvan.com',
'actblue.com',
'democrats.org',
'gop.com',
'republicanparty.com'
];
// Build a Gmail search query like: from:(ngpvan.com OR actblue.com OR ...)
const searchQuery = 'from:(' + politicalDomains.join(' OR ') + ') in:inbox OR category:promotions';
// Search threads matching the query
const threads = GmailApp.search(searchQuery, 0, 500); // adjust batch size if needed
if (threads.length > 0) {
GmailApp.moveThreadsToSpam(threads);
}
Logger.log(`Moved ${threads.length} threads to spam.`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment