Skip to content

Automate Gmail with n8n: Labels, Digests and Auto-Replies

This page may contain affiliate links.

If your Gmail inbox looks like a car boot sale after a busy week, n8n is the tool that quietly tidies it while you get on with actual work. Unlike Zapier or Make, n8n can be self-hosted for free (or run cheaply on n8n Cloud), and its Gmail node gives you proper access to labels, threads and drafts. In this guide we will build three genuinely useful automations: automatic labelling and filing, a morning digest email, and auto-replies that do not make you sound like a robot. Everything here uses the standard Gmail node and a few lines of JavaScript in a Code node where needed.

Getting n8n talking to Gmail

First, create a Gmail credential in n8n. Go to Credentials > New > Gmail OAuth2 API. You will need a Google Cloud project with the Gmail API enabled and an OAuth consent screen configured. The scopes you want are:

  • https://www.googleapis.com/auth/gmail.modify (read, label, archive, mark read)
  • https://www.googleapis.com/auth/gmail.send (send replies)
  • https://www.googleapis.com/auth/gmail.compose (create drafts)

Add https://YOUR-N8N-DOMAIN/rest/oauth2-credential/callback as an authorised redirect URI. If you are self-hosting on a Raspberry Pi or a small VPS, this works fine — just make sure the domain is reachable over HTTPS, otherwise Google will refuse the callback.

One practical tip: if you are running n8n on a home server, a cheap UPS keeps it alive through brief power cuts. Something like this mini UPS for Raspberry Pi is a sensible few-quid insurance policy.

Workflow 1: Auto-label and file incoming mail

This is the workhorse. Use a Gmail Trigger node set to poll every minute with the filter is:unread -label:auto-processed. That filter is important — it stops the workflow re-processing the same emails on every poll.

Chain it into a Switch node (or an IF node if you only have two branches). Here is a realistic set of rules:

  • From domain contains stripe.com or subject matches /invoice|receipt/i → label Finance/Receipts, archive
  • From contains @yourclient.co.uk → label Clients, mark as important
  • Subject or body matches /unsubscribe|newsletter/i → label Newsletters, skip inbox
  • Anything else → label Inbox/Unsorted

In the Gmail node, use the Add Label operation and pass the label ID. You can get label IDs by adding a one-off Gmail node with the Get Many Labels operation — run it once, copy the IDs into your workflow, then delete the node. Labels with slashes like Finance/Receipts must already exist in Gmail; n8n will not create them for you.

Finish the workflow by adding the auto-processed label to every message the trigger picked up. That single step prevents duplicate runs and is the difference between a workflow that works and one that spams you with the same email twelve times an hour.

Workflow 2: A morning digest you will actually read

Instead of checking email constantly, batch it. Build a Schedule Trigger set to fire at 07:30 on weekdays. Then add a Gmail > Get Many Messages node with the query:

is:unread newer_than:1d -label:Newsletters -label:Finance/Receipts

Set Return All to false and limit to 50. Feed the results into a Code node to build a tidy HTML summary. Here is a compact version you can paste in:

const items = $input.all();
const rows = items.map(i => {
  const m = i.json;
  const from = (m.From && m.From.value && m.From.value[0].address) || 'unknown';
  const subject = m.Subject || '(no subject)';
  const snippet = (m.snippet || '').slice(0, 140);
  return `<li><strong>${from}</strong> &mdash; ${subject}<br><em>${snippet}</em></li>`;
}).join('');
return [{ json: { html: `<h2>Your morning digest</h2><ul>${rows}</ul>` } }];

Then a Gmail > Send node with your own address as the recipient, subject Morning digest — {{ $now.format('cccc d LLLL') }}, and the message body set to the html field. Set Email Type to HTML. Two minutes of setup, and you get one calm email instead of forty panic-inducing notifications.

If you would rather skip the build entirely, we have done the fiddly parts for you: n8n Starter Workflows is a pack of plug-and-play n8n templates you can import in minutes, including a Gmail triage workflow very close to the one above. It starts from £9, which is roughly the cost of a couple of coffees, and saves you an evening of debugging OAuth scopes.

Workflow 3: Auto-replies that sound human

Auto-replies have a bad reputation because most of them are terrible. The trick is to be narrow. Do not try to auto-reply to everything — pick one or two low-risk categories and write a short, honest template.

A good pattern: a Gmail Trigger filtered to is:unread -label:auto-replied, then an IF node checking that the sender is not yourself (otherwise you will reply to your own digest) and that the subject matches something specific, like /enquiry|quote request/i. Then a Gmail > Reply node using the message ID from the trigger, with a body like:

Thanks for getting in touch — I have seen your message and will come back to you properly within one working day. If it is urgent, feel free to call.

Finally, add the auto-replied label so it only ever fires once per thread. If you want to be clever, swap the Gmail Reply node for a Create Draft node instead. n8n will park a ready-written reply in your drafts folder and you just hit send after a glance. That gets you 90% of the time saving with none of the risk of saying something daft automatically.

You can also add a delay with a Wait node — say 15 minutes — so replies do not fire at 3am and look suspiciously robotic.

Keeping it tidy and cheap

Three habits keep these workflows running for years rather than weeks. First, always use a marker label to prevent re-processing. Second, log failures to a separate sheet or a Slack message so a broken OAuth token does not silently kill your triage. Third, keep your rules in a Set node at the top of the workflow so you can edit keywords without touching the logic.

On cost: self-hosted n8n is free apart from whatever you run it on, and a small VPS or a spare Raspberry Pi handles this workload easily. n8n Cloud has paid tiers — check the current pricing on their site, as it changes.

Gmail is one of the last places most of us still do manual labour every single day. Twenty minutes with n8n turns it into something that files itself, summarises itself and occasionally answers on your behalf. Start with the labelling workflow — it is the easiest win — then layer the digest on top once you trust it. Your inbox will not thank you, but your Monday morning certainly will.

Written by

Richard Tucker

View all posts →