Created
October 26, 2025 17:30
-
-
Save chasecmiller/c0a139066a5102305717b5503d447957 to your computer and use it in GitHub Desktop.
Google Script to help filter political emails to spam.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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