r/GoogleAppsScript • u/lizziehorvitz • May 11 '26
Guide Built a Gmail script that auto-detects flight confirmations and calculates carbon emissions
I wanted to automatically offset my flights but kept forgetting. So I built a Google Apps Script to handle it.
Every Monday it runs a broad Gmail search for flight-related emails from the past week, then calls the Claude API to read each one and determine if it's actually a flight confirmation. If it is, it extracts the route, cabin class, and passenger count, calculates CO2e using BEIS/ICAO methodology with radiative forcing, and sends me a summary email with the footprint and an offset link.
A few things I had to solve:
Email parsing. Airlines don't have a standard format. "Your Cleveland Trip (C2YZYT) is almost here!" is a Southwest confirmation. Regex was never going to cut it, so I'm passing the subject and body to Claude and letting it figure out what's a real booking and what isn't.
Deduplication. Airlines send multiple emails per booking — confirmation, receipt, reminder, check-in. The script asks Claude to extract the confirmation code from each email and skips anything it's already seen in that run.
The Gmail search query. Started with tight subject-line keywords and kept missing confirmations. Ended up broadening it to catch emails from known airline domains too, then letting Claude filter false positives on the backend.
Script runs on a time-based trigger, labels processed emails in Gmail, and sends the summary to my own address. Works well so far.
Happy to share the code if useful.
View all comments
Show parent comment
1
u/lizziehorvitz May 11 '26
Fair points for production systems. This is a personal script running in your own Google account under your own API key, so the threat model is pretty different. Worth noting for anyone building on top of it though.