Home / Software / n8n / n8n + Gmail: How to Automate Your Email

n8n + Gmail: How to Automate Your Email

n8n + Gmail: How to Automate Your Email

Email is still the backbone of business communication, and for most UK small businesses running Google Workspace, the inbox never stops filling up. n8n — the open-source workflow automation platform — connects directly to Gmail via OAuth2, letting you build automations that sort, forward, summarise, and draft replies without touching a line of code. Whether you want to route customer enquiries automatically, get a daily digest of messages from a key client, or use AI to draft replies for your review, n8n makes it practical. This guide walks through setting up the Gmail credential and building three workflows you can deploy today.

Setting Up the Gmail Credential in n8n

n8n connects to Gmail using OAuth2, which means you authenticate once through Google and n8n handles the token refresh automatically. To get started, you need a project in Google Cloud Console.

  1. Create a Google Cloud project. Go to console.cloud.google.com, click the project dropdown at the top and select New Project. Give it a name — something like “n8n Automations” — and click Create.
  2. Enable the Gmail API. From the left menu, go to APIs & Services → Library, search for “Gmail API” and click Enable.
  3. Configure the OAuth consent screen. Go to APIs & Services → OAuth consent screen. Choose External unless you have a Google Workspace organisation, in which case choose Internal. Fill in the app name, support email, and developer email. Under Scopes, add https://www.googleapis.com/auth/gmail.modify — this covers reading, sending, and labelling.
  4. Create OAuth credentials. Go to APIs & Services → Credentials → Create Credentials → OAuth client ID. Select Web application. Under Authorised redirect URIs, paste the redirect URI from n8n — you’ll find this inside the Gmail credential screen in n8n (it looks like https://your-n8n-instance/rest/oauth2-credential/callback). Save the Client ID and Client Secret.
  5. Complete the flow in n8n. In n8n, go to Credentials → New → Gmail OAuth2 API. Paste in the Client ID and Client Secret, then click Connect my account. Google will prompt you to sign in and grant access. Once authorised, the credential is ready to use in any Gmail node.

If your n8n instance is self-hosted — which is common for teams mindful of GDPR — all email content processed through your workflows stays on your own server. This is a significant advantage for UK businesses subject to UK GDPR: you’re not routing sensitive message content through a third-party cloud platform. If you use n8n Cloud, treat it like any other data processor and check that it is covered under your data processing agreements.

Workflow 1: Auto-Label and Forward Customer Enquiries

This workflow watches your inbox for new emails matching a search query, checks the sender or subject, applies a label, marks the message as read, and optionally forwards it to a colleague or shared inbox.

  • Gmail Trigger node: Set the trigger to New Email. In the search query field, enter something like subject:enquiry is:unread to watch only for unread messages with “enquiry” in the subject. The trigger polls Gmail on your chosen interval — every minute is fine for most use cases.
  • IF node: Add a condition to check the sender’s email domain — for example, {{ $json.from }} contains @yourdomain.co.uk to separate internal from external senders. Route external senders down the True branch.
  • Gmail node (label + mark read): Use the Modify action. Set it to add a label (e.g. “Enquiries”) and mark the message as read. Pass the message ID from the trigger using {{ $json.id }}.
  • Gmail node (forward): Add a second Gmail node using the Send action. Set the To address to your shared inbox or a colleague. Pull the original subject with {{ $json.subject }} and the body with {{ $json.text }}.

This is particularly useful for sole traders and small teams who receive enquiries on a general inbox but need them routed to the right person without manually forwarding every message.

Workflow 2: Daily Email Digest

Instead of checking a client’s messages throughout the day, this workflow runs once each morning and sends you a summary of everything they’ve sent in the past 24 hours.

  • Schedule Trigger node: Set it to run at 8:00am Monday to Friday.
  • Gmail node (get messages): Use the Get Many operation. In the search query, enter from:[email protected] newer_than:1d. Set a reasonable limit — 50 messages is usually more than enough.
  • Aggregate node: Concatenate the subject lines and snippets from all returned messages into a single string. Use an expression like {{ $json.subject }} — {{ $json.snippet }} joined with line breaks.
  • Send Email node (or Gmail node): Send the digest to yourself. The body contains the aggregated list of messages from the past 24 hours, formatted as a plain-text summary.

You can extend this by adding a filter before the aggregate step — for example, only include messages where the snippet contains certain keywords, or exclude automated notifications using -subject:notification in the search query.

Workflow 3: AI-Drafted Replies for New Enquiries

This workflow catches new emails on a specific label, sends the message content to an AI model, and saves the generated reply as a Gmail draft — ready for you to review before sending.

  • Gmail Trigger node: Watch for new emails with the label “Enquiries” (applied by Workflow 1, or manually). Search query: label:Enquiries is:unread.
  • OpenAI or Ollama node: Pass the email body to the AI. A prompt like “You are a helpful assistant. Draft a professional reply to the following enquiry. Be concise and friendly. Enquiry: {{ $json.text }}” works well as a starting point. If you’re self-hosting Ollama on your own server, you can process email content locally without sending it to any external API — a clean GDPR story.
  • Gmail node (create draft): Use the Create Draft action, not Send. Set the To field to the sender’s address ({{ $json.from }}), the Subject to Re: {{ $json.subject }}, and the body to the AI’s output ({{ $json.text }} from the AI node).

Do not configure this — or any workflow — to send emails automatically without human review. AI-drafted replies can misread tone, miss context, or include errors. Saving to Drafts gives you full control: the reply is ready to go, you just need to check it and hit Send. This also keeps you compliant with any professional obligations around client communications.

Gmail Search Queries Worth Knowing

The search query field in the Gmail Trigger and Get Messages nodes accepts the same syntax as the Gmail search bar. Useful examples: from:[email protected] filters by sender; subject:invoice matches a word in the subject line; has:attachment limits results to messages with files attached; newer_than:7d restricts to the last seven days; and label:Enquiries is:unread combines a label filter with read status. Combining operators with spaces acts as AND — so from:client.com has:attachment newer_than:1d finds attachments from that sender in the last 24 hours.

OAuth2 vs SMTP: Which Should You Use?

n8n supports both Gmail OAuth2 and a standard SMTP credential. OAuth2 is the better choice for Gmail and Google Workspace accounts: it supports reading, labelling, drafting, and sending, and it does not require you to enable “less secure app access” or manage app passwords. SMTP is simpler to configure and works with any email provider, but it can only send messages — you cannot read, label, or draft via SMTP. For the workflows above, OAuth2 is required. Use SMTP only if you need a lightweight send-only integration with a non-Gmail provider.

Google Workspace is the dominant email platform for UK SMBs, and n8n’s Gmail integration covers the full range of what the API offers. Combined with a self-hosted n8n instance, you get powerful email automation with your data remaining under your control — which matters both practically and under UK GDPR.