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.
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
- Go to console.cloud.google.com and create a new project (or select existing).
- Navigate to APIs & Services → Library and enable the Gmail API.
- Go to APIs & Services → OAuth consent screen.
- Choose External user type and fill in the app name (e.g. "n8n Gmail Bot") and your email.
- Add the scope
https://mail.google.com/(full Gmail access) or more specific scopes as needed. - Add your own email as a Test User (required while the app is in testing mode).
2. Create OAuth2 Credentials
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID.
- Select Web Application as the application type.
- Add n8n's OAuth callback URL as an authorized redirect URI:
https://your-n8n-instance.com/rest/oauth2-credential/callback - Copy the Client ID and Client Secret.
3. Configure in n8n
- In n8n, go to Credentials → New → Gmail OAuth2 API.
- Enter your Client ID and Client Secret.
- Click Connect and follow the Google authorization flow.
- Grant the requested permissions — n8n will store the token securely.
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:
Available Trigger Events
| Event | Fires When | Best For |
|---|---|---|
| Email Received | New email arrives in inbox (or label) | Support tickets, contact forms, order confirmations |
| Label Added | A label is applied to an email | Triggering workflows from Gmail's own filters/rules |
Trigger Output Fields
Each triggered email produces a rich JSON object you can use in downstream nodes:
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
Filter by Subject Keywords
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:
from:boss@company.com has:attachment).Sending Emails with n8n
The Send Email operation is straightforward but has important options:
Sending with Attachments
Attach files from previous nodes (e.g. a PDF generated by a Code node, or a file downloaded via HTTP Request):
Auto-Responder Workflow
A classic Gmail automation: automatically acknowledge incoming support emails while a human reviews them.
Workflow Structure
- Gmail Trigger — listens for emails with label "Support".
- IF Node — excludes auto-replies (check:
$json.fromdoes not contain "noreply" and$json.subjectdoes not start with "Re:"). - Gmail → Reply — sends the acknowledgment using the original
threadId. - Gmail → Add Label — applies "Auto-Replied" label to track processed emails.
- Slack — notifies the support team with email details.
Daily Email Digest Workflow
Aggregate important emails into a single daily summary — great for monitoring newsletters, alerts, or reports.
- Schedule Trigger — runs at 7 AM every weekday.
- Gmail → Get Many Messages — searches for emails from the past 24 hours matching a query.
- Code Node — formats the emails into an HTML digest table.
- Gmail → Send Email — sends the digest to your personal or team email.
Forward-and-Process Pattern
Forward incoming emails to another service while processing them in parallel:
- Gmail Trigger — new email arrives.
- Set Node — extract the email body and attachments.
- 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
- Gmail Trigger — new email in the "Support" label.
- IF Node — filters out auto-replies and spam.
- 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.
- IF Node — checks AI confidence score (if the model indicates it can't answer confidently, route to human).
- Gmail → Reply (true branch) — sends the AI-generated response.
- Slack (false branch) — notifies a human agent to take over.
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.
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
$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.