Why there is no "on new email" trigger
Apps Script exposes a small set of simple triggers — onOpen, onEdit, onFormSubmit — and a broader set of installable ones. Gmail is conspicuously absent from both lists. Google has never shipped a push trigger that fires the moment a message lands. The closest thing is a Gmail add-on's contextual trigger, which only fires when the user opens a specific message in the UI. That is not what you want when you need headless automation.
The real answer is a time-driven trigger set to run every 1 or 5 minutes, paired with a search query that acts as a queue. GmailApp.search() accepts the same operators as the Gmail search bar — is:unread, from:[email protected], subject:invoice, has:attachment — so you can scope the queue tightly. The polling delay is real: if your trigger fires every 5 minutes, worst-case latency is 5 minutes. For most automation that is fine; for true real-time you need a different tool (Pub/Sub via Cloud Functions, or a third-party webhook service).
I keep the polling interval at 5 minutes in production. Every 1 minute sounds better, but Apps Script counts trigger executions against a daily quota (6 minutes of CPU for free accounts, 30 for Workspace). A tight loop on a busy inbox burns that quota fast.