Automate Gmail with n8n: Triggers, Sending & Filtering Emails 2026

Email remains the backbone of business communication, and automating it can save hours every week. n8n's Gmail integration covers the full email lifecycle: receiving and filtering incoming mail, sending outbound messages, labeling, archiving, and even combining Gmail with AI for intelligent email handling.

This guide walks you through the complete setup — from OAuth credentials to advanced workflow patterns including AI-powered auto-responders and daily digest emails.

⚡ Generate Gmail workflows instantly

Skip the setup and describe your Gmail automation at Scriflow to get a ready-to-import n8n JSON in seconds.

Setting Up Gmail OAuth Credentials

Gmail requires OAuth2 authentication. Here's the complete setup process:

1. Create a Google Cloud Project

  1. Go to console.cloud.google.com and create a new project (or select existing).
  2. Navigate to APIs & Services → Library and enable the Gmail API.
  3. Go to APIs & Services → OAuth consent screen.
  4. Choose External user type and fill in the app name (e.g. "n8n Gmail Bot") and your email.
  5. Add the scope https://mail.google.com/ (full Gmail access) or more specific scopes as needed.
  6. Add your own email as a Test User (required while the app is in testing mode).

2. Create OAuth2 Credentials

  1. Go to Credentials → Create Credentials → OAuth 2.0 Client ID.
  2. Select Web Application as the application type.
  3. Add n8n's OAuth callback URL as an authorized redirect URI: https://your-n8n-instance.com/rest/oauth2-credential/callback
  4. Copy the Client ID and Client Secret.

3. Configure in n8n

  1. In n8n, go to Credentials → New → Gmail OAuth2 API.
  2. Enter your Client ID and Client Secret.
  3. Click Connect and follow the Google authorization flow.
  4. Grant the requested permissions — n8n will store the token securely.
💡 Google Workspace users

For Google Workspace (formerly G Suite) accounts, use an Internal OAuth consent screen type. You won't need to add test users, and the app won't require Google verification.

Gmail Trigger Node

The Gmail Trigger node polls your inbox for new messages matching your criteria. This is how you build reactive email workflows:

Trigger Type: Email Received Poll Time: Every minute Filters: Include Spam/Trash: false Label Names: INBOX // or a custom label Sender Filter: noreply@github.com // optional: filter by sender

Available Trigger Events

EventFires WhenBest For
Email ReceivedNew email arrives in inbox (or label)Support tickets, contact forms, order confirmations
Label AddedA label is applied to an emailTriggering workflows from Gmail's own filters/rules

Trigger Output Fields

Each triggered email produces a rich JSON object you can use in downstream nodes:

{ "id": "18e3c2f4d1a0b9c5", // Gmail message ID "threadId": "18e3c2f4d1a0b9c5", "from": "alice@example.com", "to": "you@yourcompany.com", "subject": "Support request: can't login", "date": "2026-03-13T09:30:00Z", "text": "Hi, I'm having trouble logging in...", "html": "<p>Hi, I'm having trouble...</p>", "labelIds": ["INBOX", "UNREAD"], "attachments": [] }

Filtering Emails by Sender and Subject

Not every email should trigger the same action. Use IF nodes after the trigger to route different emails through different paths:

Filter by Sender Domain

// IF node: check if email is from a specific domain Condition: {{ $json.from }} contains "@github.com" // OR: check against an array of known senders Condition: {{ ['support@stripe.com', 'noreply@github.com'] .includes($json.from) }} is true

Filter by Subject Keywords

// IF node: check subject contains keywords Condition: {{ $json.subject.toLowerCase() }} contains "urgent" // Using regex for more complex patterns Condition: {{ /^(support|help|bug):/i.test($json.subject) }} is true

Using Gmail's Native Label Filtering

A cleaner approach: create Gmail Filters in your Gmail settings to automatically apply labels to emails. Then set your n8n trigger to only fire on emails with that specific label. This moves the filtering logic into Gmail where it belongs, keeping your n8n workflow clean.

Gmail Node Actions

The Gmail node supports all major email operations:

Send Email
action
Compose and send a new email from your Gmail account. Supports HTML, CC, BCC, and attachments.
Reply to Email
action
Reply in the same thread using the original message ID. Maintains conversation context.
Add Label
action
Apply one or more labels to a message. Useful for categorization and triggering other rules.
Remove Label
action
Remove a label (e.g. remove UNREAD after processing, or remove a processing label).
Move to Trash
action
Delete an email after processing (e.g. auto-archive spam or processed notifications).
Get Many Messages
read
Search for emails using Gmail query syntax (e.g. from:boss@company.com has:attachment).

Sending Emails with n8n

The Send Email operation is straightforward but has important options:

Resource: Message Operation: Send To: {{ $json.customerEmail }} Subject: Your order #{{ $json.orderId }} has shipped! 🚀 Email Type: HTML HTML Body: <p>Hi {{ $json.firstName }},</p> <p>Your order <strong>#{{ $json.orderId }}</strong> is on its way.</p> <p>Track it here: <a href="{{ $json.trackingUrl }}">Track Package</a></p> <p>Best,<br>The Team</p> CC: orders@yourcompany.com

Sending with Attachments

Attach files from previous nodes (e.g. a PDF generated by a Code node, or a file downloaded via HTTP Request):

// After a node that produces binary data: Attachments: - Input Data Field Name: data File Name: report-{{ $now.toFormat('yyyy-MM-dd') }}.pdf

Auto-Responder Workflow

A classic Gmail automation: automatically acknowledge incoming support emails while a human reviews them.

Workflow Structure

  1. Gmail Trigger — listens for emails with label "Support".
  2. IF Node — excludes auto-replies (check: $json.from does not contain "noreply" and $json.subject does not start with "Re:").
  3. Gmail → Reply — sends the acknowledgment using the original threadId.
  4. Gmail → Add Label — applies "Auto-Replied" label to track processed emails.
  5. Slack — notifies the support team with email details.
// Reply node configuration Resource: Message Operation: Reply Message ID: {{ $('Gmail Trigger').item.json.id }} Thread ID: {{ $('Gmail Trigger').item.json.threadId }} HTML Body: <p>Hi {{ $json.from.split('@')[0] }},</p> <p>Thanks for reaching out! We've received your message and our team will get back to you within 24 hours.</p> <p>Your ticket number: <strong>#{{ $now.toMillis() }}</strong></p> <p>The Support Team</p>

Daily Email Digest Workflow

Aggregate important emails into a single daily summary — great for monitoring newsletters, alerts, or reports.

  1. Schedule Trigger — runs at 7 AM every weekday.
  2. Gmail → Get Many Messages — searches for emails from the past 24 hours matching a query.
  3. Code Node — formats the emails into an HTML digest table.
  4. Gmail → Send Email — sends the digest to your personal or team email.
// Gmail search query for yesterday's emails Query: after:{{ $now.minus({days: 1}).toFormat('yyyy/MM/dd') }} before:{{ $now.toFormat('yyyy/MM/dd') }} label:important -from:me Maximum Results: 50 // Code node: build HTML digest const items = $input.all(); const rows = items.map(item => ` <tr> <td>${item.json.from}</td> <td>${item.json.subject}</td> <td>${item.json.date}</td> </tr> `).join(''); return [{ json: { digestHtml: `<table>${rows}</table>`, count: items.length } }];

Forward-and-Process Pattern

Forward incoming emails to another service while processing them in parallel:

  1. Gmail Trigger — new email arrives.
  2. Set Node — extract the email body and attachments.
  3. Two parallel branches:
  • Branch A: Forward the original email to a team inbox using the Gmail Send operation.
  • Branch B: Save the email details to Airtable/Google Sheets for logging and analysis.

Combining Gmail with AI for Smart Email Handling

This is where n8n's Gmail integration becomes truly powerful. By routing emails through an AI model, you can build context-aware automated responses:

AI Customer Support Workflow

  1. Gmail Trigger — new email in the "Support" label.
  2. IF Node — filters out auto-replies and spam.
  3. HTTP Request → OpenAI — sends the email subject and body to GPT-4o with a system prompt defining the support agent persona and your product knowledge.
  4. IF Node — checks AI confidence score (if the model indicates it can't answer confidently, route to human).
  5. Gmail → Reply (true branch) — sends the AI-generated response.
  6. Slack (false branch) — notifies a human agent to take over.
// OpenAI HTTP Request body { "model": "gpt-4o", "messages": [ { "role": "system", "content": "You are a helpful support agent for Acme Corp. Answer customer emails professionally and concisely. If you're unsure, respond with ESCALATE." }, { "role": "user", "content": "Subject: {{ $json.subject }}\n\n{{ $json.text }}" } ], "max_tokens": 800 }

Tips for Avoiding Spam Filters

When sending automated emails via Gmail, follow these best practices to ensure deliverability:

  • Personalize every email: Include the recipient's name in the subject or body. Generic mass emails trigger spam filters.
  • Avoid spam trigger words: Words like "FREE!", "URGENT", "GUARANTEED", and excessive capitalization or exclamation marks reduce deliverability.
  • Send from a warmed-up address: Don't use a brand new Gmail account for bulk automation. Use an established address with a history of real email activity.
  • Respect reply-to headers: Set a valid reply-to address so recipients (and spam filters) can see the email is legitimate.
  • Add unsubscribe links: For any marketing-adjacent automation, include a way for recipients to opt out. Gmail's algorithms reward this.
  • Rate-limit your sends: Gmail's API has a quota of ~500 emails per day for regular accounts. Use a Wait node between sends if processing large batches.
  • Plain text fallback: Always include both HTML and plain text versions. Some spam filters penalize HTML-only emails.
📌 Gmail API send limits

Standard Gmail accounts: ~500 emails/day via API. Google Workspace accounts: up to 2,000 emails/day. For higher volumes, use a dedicated transactional email service (SendGrid, Mailgun, Postmark) via the HTTP Request node instead.

Frequently Asked Questions

Can n8n read emails from specific Gmail labels only?
Yes. In the Gmail Trigger node, set the Label Names field to a specific label (e.g. "Support", "INBOX", "UNREAD"). The trigger will only fire for emails with that label applied. You can also use Gmail's built-in filters to auto-label emails from certain senders before n8n picks them up.
How do I prevent an auto-responder from replying to other automated emails?
Add an IF node that checks: (1) $json.from does not contain "noreply", "no-reply", "donotreply"; (2) $json.subject does not start with "Re:", "Fwd:", "Automatic reply"; and (3) $json.labelIds does not include "SENT". This catches most auto-reply scenarios.
Can I access Gmail attachments in n8n?
Yes. The Gmail Trigger and Get Message operations return attachment metadata. To download the actual file content, use the Download Attachment operation in the Gmail node, which returns binary data you can then process, save to Google Drive, or forward.
How is n8n's Gmail integration different from Zapier's?
n8n gives you full control: complex branching, code execution, unlimited steps, and self-hosting. Zapier is simpler but more limited in logic complexity. n8n also supports combining Gmail with any other node in a single workflow — there's no "app limit" per zap. And with Scriflow, you can generate Gmail workflows in seconds.
Can Scriflow generate my Gmail automation workflow?
Absolutely. Go to scriflow.busca.software, describe your Gmail workflow in plain English (e.g. "When a new Gmail email with subject containing 'invoice' arrives, extract the amount from the body using AI, save it to Google Sheets, and send a Slack message"), and get ready-to-import n8n JSON instantly.