All workflows
Gmail logoGoogle Sheets logo

Save matching emails to a spreadsheet

Saves each new Gmail message that matches your search as a row in your spreadsheet, and never saves the same message twice.

On new email in Gmail2 apps6 steps

Apps it connects

Authenticate each one once and the workflow is ready to run.

What it does

The integration steps this workflow runs, in the order it first runs them.

  1. 1GmailNew email trigger
  2. 2GmailList emails
  3. 3GmailAdd label to message
  4. 4GmailGet message headers
  5. 5Google SheetsAppend row
  6. 6GmailRemove label from message

How it works

Everything the template sets up, and what to fill in before the first run.

When mail arrives in Gmail this looks for the messages your search matches and writes one row per message into your spreadsheet. The row records when the message was sent, who sent it, who it was sent to, its subject, an excerpt of the body, the Gmail message id and a link that opens the message in Gmail - in that column order, so give your tab those headings.

Nothing is saved twice. Each message is labelled the moment it is picked up, and the Gmail search excludes that label - so a message that has already been saved is never even fetched on a later run. The label goes on before the row is written, deliberately: a spreadsheet that cannot be written to then costs nothing, because the label is taken off again, the message is tried again on the next run, and the run ends in failure so you can see it - rather than the same rows being added again on every run until somebody notices.

New mail is what wakes it, but the search is what does the work - so several matching messages landing at once are all saved, not just the first, and a backlog is worked through 'maxEmailsPerRun' at a time. That setting bounds how many messages one run reads and saves; the rest are picked up by the next run. Your setting is turned into a number first, so a cap of 12 means twelve and not the text '12'.

'excerptLength' is how many characters of the message body go into the Excerpt column - 300 to start with, and 0 leaves the column empty. When Gmail gives no body text the message's preview snippet is used instead. If Gmail will not give up a message's headers, the row records the time it was saved instead of the time it was sent and leaves the To column empty, and says so in the run log.

Fill in 'emailSearch' with a Gmail search that picks out the mail to save - for example from:billing@example.com, subject:invoice or has:attachment - and 'spreadsheetUrl' with the spreadsheet. 'sheetTabName', 'savedLabel' and 'gmailAccountIndex' (the number in the mail.google.com/mail/u/0/ address of the Google account the sheet's links should open in) have working defaults. Naming a sender on the trigger step narrows what wakes it; left empty, any new mail wakes it and the search decides what is saved.

gmailgoogle sheetsemailbackupspreadsheetsearch

Start from a workflow that already works.

Add "Save matching emails to a spreadsheet" to your workspace, connect its apps, and make it yours. No credit card required.

Free plan available · No credit card required