
Parse Emails into Google Sheets Automatically (Free)
To parse emails into Google Sheets for free, let Gmail label the messages and let Apps Script do the rest: a Gmail filter puts a to-parse label on the emails you care about, a script runs every few minutes, extracts the fields you need from each new message, appends them as rows and moves the thread to parsed. About 60 lines of code replace a $30-130 a month parser subscription for most small businesses, and the daily ceiling (20,000 email read/write operations on a personal Gmail account, 50,000 on Google Workspace) is far above what an order or lead inbox produces.
This post covers the whole inbound pipeline: what's worth extracting, when regex is enough and when you need AI, how to avoid duplicate rows, what it costs next to Parseur and Mailparser, and the four ways it breaks. If you're after the outbound side, sending emails from a sheet, our comparison of outbound email options for Google Sheets covers that. And if you'd rather have mail arrive at a dedicated address than read it out of Gmail, our Mailgun guide routes inbound email straight into rows.
The pattern: label, search, extract, relabel
Every reliable email parser we've built in Apps Script has the same four parts:
| Step | Where it happens | Why it's built this way |
|---|---|---|
| 1. Label | A Gmail filter (e.g. from:orders@yourshop.com → apply to-parse) | Gmail does the sorting for free, and you can change the rule without touching code |
| 2. Search | GmailApp.search('label:to-parse', 0, 50) | The paged form reads a fixed batch per run, so one busy morning can't time out the script |
| 3. Extract | A parser function per email type | Keeps "what does an order email look like" separate from the plumbing |
| 4. Write, then relabel | One setValues() call, then to-parse → parsed | The sheet gets the data before the email is marked done, so a crash never loses a row |
Here's the core of it:
function parseInbound() {
const lock = LockService.getScriptLock();
if (!lock.tryLock(5000)) return; // previous run still busy: skip this one
try {
const sheet = SpreadsheetApp.getActive().getSheetByName('Orders');
const last = sheet.getLastRow();
const seen = new Set(last > 1
? sheet.getRange(2, 1, last - 1, 1).getValues().flat().map(String) : []);
const todo = GmailApp.getUserLabelByName('to-parse');
const done = GmailApp.getUserLabelByName('parsed') || GmailApp.createLabel('parsed');
const failed = GmailApp.getUserLabelByName('parse-failed') || GmailApp.createLabel('parse-failed');
const threads = GmailApp.search('label:to-parse', 0, 50);
const rows = [], ok = [], bad = [];
for (const thread of threads) {
let threadOk = true;
for (const msg of thread.getMessages()) {
const id = msg.getId();
if (seen.has(id)) continue; // already in the sheet
const data = extractOrder(msg.getPlainBody());
if (data) { rows.push([id, msg.getDate(), msg.getFrom(), ...data]); seen.add(id); }
else threadOk = false;
}
(threadOk ? ok : bad).push(thread);
}
if (rows.length) {
sheet.getRange(sheet.getLastRow() + 1, 1, rows.length, rows[0].length).setValues(rows);
SpreadsheetApp.flush(); // data is safe before we relabel
}
ok.forEach(t => t.removeLabel(todo).addLabel(done));
bad.forEach(t => t.removeLabel(todo).addLabel(failed));
} finally {
lock.releaseLock();
}
}
Column A holds the Gmail message ID. Format that column as plain text (Format → Number → Plain text) before the first run, so Sheets never turns an ID that happens to be all digits into a number.
Install it with a time-driven trigger. everyMinutes() accepts 1, 5, 10, 15 or 30; for most order and lead inboxes, every 5 minutes is plenty:
function install() {
ScriptApp.newTrigger('parseInbound').timeBased().everyMinutes(5).create();
}
At 5-minute intervals that's 288 runs a day. A run that finds nothing takes a second or two, so even a busy day stays well inside the 90 minutes of daily trigger runtime a free Gmail account gets (6 hours on Workspace).
What's worth extracting
The best candidates are emails that arrive often, look the same every time, and currently get retyped by a person.
| Email type | Typical fields | Usually parsed with |
|---|---|---|
| Shop order notifications | Order number, customer, email, items, total, shipping method | Regex: the shop platform generates them from one template |
| Website / form leads | Name, phone, email, message, source page, UTM tags | Regex, or read the structured block most form tools send |
| Marketplace and payment notices | Transaction ID, amount, fee, payout date | Regex |
| Supplier invoices (PDF attached) | Supplier, invoice number, date, net, tax, total | Attachment to Drive, then OCR or AI vision |
| Quote requests and free-text enquiries | Product, quantity, deadline, budget | AI extraction |
| Booking and delivery confirmations | Reference, date, time, address | Regex |
Order and lead emails are where the payoff is fastest. In the inboxes we've automated, the manual version is someone opening each notification and typing five or six fields into a sheet, a few minutes per email and a steady source of typos in phone numbers and totals. Once the rows land automatically, the sheet can feed everything downstream: a CRM tab, a dispatch list, a daily summary.
Attachments follow the same loop. msg.getAttachments({ includeInlineImages: false }) returns the real attachments without logos and signature images. Save each one with folder.createFile(blob) and put the file URL in the row. Reading the inside of a PDF invoice is a separate problem; our walkthrough on extracting invoice data with AI vision models shows that half, using photos sent over WhatsApp, and the same extraction step works on email attachments.
Regex or AI extraction?
This is the main design decision, and the answer is usually "both, in that order."
Regex is right when a machine wrote the email. A shop's order notification has the same labels in the same places every time, so a few patterns read it perfectly, instantly and for free:
function extractOrder(body) {
const grab = re => ((body.match(re) || [])[1] || '').trim();
const order = grab(/Order\s*#\s*([A-Z0-9-]+)/i);
if (!order) return null; // not an order email: flag it
const total = grab(/Total:\s*[^\d]*([\d.,]+)/i).replace(/,/g, ''); // assumes 1,234.56 format
return [order, grab(/Customer:\s*(.+)/i), grab(/Email:\s*(\S+@\S+)/i), Number(total) || ''];
}
Use getPlainBody() rather than parsing HTML. It strips the markup, and most notification emails read cleanly as text. Returning null when the key field is missing matters: that's what sends the thread to parse-failed for a human instead of writing a half-empty row.
AI extraction is right when a person wrote the email. "Hi, could you quote 40 of the blue ones, ideally before the 20th?" has no fixed layout, and no regex will reliably find the quantity and deadline. A language model can, if you ask for strict JSON:
function extractWithAI(body) {
const key = PropertiesService.getScriptProperties().getProperty('GEMINI_KEY');
const model = PropertiesService.getScriptProperties().getProperty('GEMINI_MODEL');
const prompt = 'Extract {product, quantity, deadline, budget} from this email as JSON. ' +
'Use null for anything not stated. Email:\n' + body.slice(0, 8000);
const res = UrlFetchApp.fetch(
'https://generativelanguage.googleapis.com/v1beta/models/' + model + ':generateContent', {
method: 'post', contentType: 'application/json', muteHttpExceptions: true,
headers: { 'x-goog-api-key': key },
payload: JSON.stringify({
contents: [{ parts: [{ text: prompt }] }],
generationConfig: { responseMimeType: 'application/json' }
})
});
if (res.getResponseCode() !== 200) return null;
return JSON.parse(JSON.parse(res.getContentText()).candidates[0].content.parts[0].text);
}
Before the first run, open Project Settings → Script properties and add two values: GEMINI_KEY (an API key from Google AI Studio) and GEMINI_MODEL (the current model ID from Google's Gemini API docs). Keeping both out of the code means you can rotate the key or switch models without editing the script.
Three caveats from production use. AI extraction costs a small amount per email, so run regex first and send only the leftovers to the model. It is occasionally wrong with total confidence, so anything that moves money (totals, bank details) needs a validation rule or a human glance. And you're sending customer emails to a third-party API, so check the provider's data-use terms before you put personal data through it.
| Regex | AI model | |
|---|---|---|
| Best for | System-generated emails | Human-written emails |
| Cost per email | Free | Small API fee |
| Accuracy on fixed templates | Effectively perfect until the template changes | High, rarely exact |
| Breaks when | The sender changes the layout | The prompt is vague or the email is ambiguous |
| Data leaves Google | No | Yes, to the AI provider |
Avoiding duplicates and keeping labels clean
Duplicates are the most common complaint about home-made parsers, and they almost always come from one detail: in Apps Script's GmailApp service, labels are applied to threads, not messages. GmailThread has addLabel() and removeLabel(). GmailMessage has neither. So when a second notification lands in an existing thread (an order update, a repeat enquiry from the same form), the Gmail filter puts to-parse back on a thread that already holds a parsed message, and a naive script reads the whole thread and writes the original order a second time.
The fix is the one in the code above: store each message ID in column A and skip IDs you've already written. The label decides which threads to look at. The ID column decides which messages become rows. Four rules keep it tidy:
- Write first, relabel second. If the script dies between the two steps, the next run sees the thread again and the ID check stops it from duplicating.
- Take a lock.
LockServicestops two overlapping runs (a slow one and the next trigger) from both writing the same batch. - Never delete or archive the source emails in the parser. Moving them to
parsedis enough. The originals are your audit trail when someone asks where a row came from. - Give failures their own label. A
parse-failedlabel is a to-do list for a human, and a count you can alert on. Our guide to Apps Script error handling and alerts shows how to email yourself when that count grows or when the trigger itself stops.
If you re-label a thread back to to-parse by hand to re-run it, the ID column still protects you: only messages that didn't make it into the sheet get written.
What it costs compared with Parseur and Mailparser
Dedicated email parsers are good products. They give non-developers a point-and-click template editor, handle PDFs and tables, and come with support. You pay monthly for that, and the price scales with volume. Prices below are the list prices on each vendor's pricing page as of 13 October 2026:
| Option | Monthly price | What's included |
|---|---|---|
| Parseur Free | $0 | 20 pages a month, one user |
| Parseur Micro | $49 | 100 pages a month |
| Parseur Starter | $129 | 1,000 pages a month |
| Mailparser Starter (billed monthly) | $29.95 | 250 emails a month, 20 inboxes |
| Mailparser Business (billed monthly) | $99.95 | 2,000 emails a month, 50 inboxes |
| Apps Script on your Google account | $0 extra | Up to 20,000 (Gmail) / 50,000 (Workspace) email read/write operations a day |
Parseur counts an email as one page, but each page of an attached PDF counts separately, so invoice-heavy inboxes use credits faster than the email count suggests. Mailparser's annual plans are cheaper per month but come with yearly email allowances instead of monthly ones.
The Apps Script version is a one-time build plus occasional maintenance, and it's yours: the code, the data and the Gmail rules all live in your own Google account, with no per-email meter running. We make the wider case, with honest exceptions, in how to replace expensive SaaS with Google Workspace.
When to buy a parser instead: you receive dozens of different layouts from many senders and the people who maintain the rules aren't technical; you need table extraction from multi-page PDFs as a core feature; or the inbox isn't in Google at all. In those cases, Parseur or Mailparser will be cheaper than maintaining a custom script.
When it breaks, and how to notice
An email parser fails quietly. Nothing crashes. Rows just stop arriving or arrive wrong. These are the failure modes we see most:
- The sender changes their template. A shop platform update moves "Total" into a table, and the regex stops matching. The
parse-failedlabel catches this on day one instead of at month-end, provided someone watches it. - The trigger stops. A trigger stops running when its owner's account is suspended or deleted, for example after they leave the company, or when the script needs a permission nobody has re-authorised. A script that errors on every run looks alive but writes nothing. A daily "rows parsed today" check catches all three.
- The run outgrows its window. Every execution stops at 6 minutes. Reading 50 threads per run with batched writes is well under that. Reading 2,000 threads after a holiday weekend isn't, which is why the search is paged.
- The mailbox is the wrong one. In practice, the script reads the Gmail of the account it runs as. Move the inbox to a shared address, or hand the script to a colleague, and it's looking at the wrong mail. Run it from the receiving account, or forward a copy to the script's account.
- Quotas, rarely. At 20,000 or 50,000 read/write operations a day, an order inbox won't get close. A script that re-reads entire threads on every run, or loops over thousands of old messages, can.
If you build it yourself, put the label names, sheet name and parser rules in one config block at the top, so the next person can change a sender or a field without reading the whole script. If you'd rather not own it, this is a typical fixed-scope Apps Script automation project for us: one or two email types, the sheet layout and the failure alerts, scoped and quoted in writing before any work starts.
Want this built for your inbox?
If someone on your team spends part of every day copying order, lead or invoice details out of Gmail, a short look at the emails will tell us whether a free Apps Script parser covers them or whether you're better off with a paid tool.
- Book a free 30-minute discovery call. Bring two or three example emails and the sheet they should end up in. We'll tell you what's worth parsing, which method fits, and roughly what the build involves, including "just use Parseur" when that's honestly the better answer.
- Message us on WhatsApp with the email types you receive and roughly how many a day. We'll reply with how we'd parse them.
Frequently Asked Questions
Can Apps Script parse emails into Google Sheets for free?
Yes. A script attached to your sheet searches Gmail for a label (for example to-parse), reads each new message, pulls out the fields you need with regular expressions or an AI model, writes them as rows, and moves the thread to a parsed label. A time-driven trigger runs it as often as every minute. There is no per-email fee: it runs on the Google account you already have, inside Apps Script's daily quotas. The only optional cost is an AI API if you use one for messy, unstructured emails.
Can it save email attachments to Google Drive as well?
Yes. GmailMessage.getAttachments() returns each attachment as a blob, and you can pass { includeInlineImages: false } to skip logos and signature images. The script saves each blob into a Drive folder with Folder.createFile(blob) and writes the file link into the same row as the parsed data, so the sheet row and the PDF invoice stay together. Reading the contents of a PDF is a separate step, usually OCR or an AI vision model.
How many emails can Apps Script read per day?
Google's quotas page lists 20,000 email read/write operations per day (excluding sends) for a personal Gmail account and 50,000 for a Google Workspace account, reset 24 hours after the first request. Those are operations, not emails: reading a message, changing a label and marking it read each count. Triggers also have a total runtime cap of 90 minutes a day on Gmail and 6 hours on Workspace. A shop parsing a few hundred emails a day is far below both.
Does it work on a shared inbox like orders@ or info@?
Yes, if you plan for it. In practice, GmailApp works on the mailbox of the account the script runs as, so a mailbox you can open through Gmail delegation isn't something the script can read. The clean setups are: run the script from the orders@ account itself if it's a real Workspace user, have orders@ forward a copy to the account that owns the script, or, if orders@ is a Google Group, make that account a member so it receives a copy of every message.
Should I use regex or AI to extract the data?
Use regex when the emails come from a system, such as shop order notifications, form submissions or payment receipts, because the layout is identical every time and regex is free, fast and predictable. Use an AI model when humans write the emails, such as quote requests, supplier replies or forwarded invoices, because the wording changes every time. Many parsers use both: regex first, AI only for the messages regex couldn't read.



