← Andrew Sergeyev | CTO of ISD Group | Creative Digital Agency

Ukrainian | English

Setting up Gmail trigger node in N8N with OAuth

Automate e-mails, attachments, labeling on your free Gmail account

This guide helps you to build workflow in N8N that triggers each time you receive a new email.

Completely free Works with free gmail Offers a way to get your own free N8N

UPD: video version of this guide is available:

Steps Overview

1️⃣ Set up Google Cloud Console → 2️⃣ Create credential in N8N → 3️⃣ Create workflow in N8N → ✅ Done!

Prerequisites

  1. Free Gmail account
  2. Free Google Cloud Console account (no need to activate free trial)
  3. Publicly available N8N under custom domain (Don't have one? Get yours for free here)

Step 1: Log in to Google Cloud Console (GCC)

  1. Make sure you're logged in with the Google account you'd like to use (or register a new one).
  2. Open Google Cloud Console and agree to Terms of Service, click "Agree and Continue"
    Google Cloud Console - Agree and contiinue
  3. Click "Create or select project", then "New project"
    Google Cloud Console - Create or select project Google Cloud Console - New project
  4. Input project name, for example "n8n-project", click "Create"
    Google Cloud Console - Input project name
  5. Wait for it to finish creating and click on "Select project" in notifications window
    Google Cloud Console - Select project
  6. Click "APIs and Services"
    Google Cloud Console - APIs and Services
  7. Click "Enable APIs and Services" button
    Google Cloud Console - Enable APIs and Services
  8. Search for "gmail api" and click on it. Then click "Enable"
    Google Cloud Console - Search for Gmail API Google Cloud Console - Enable Gmail API
  9. Click on "OAuth consent screen" at the sidebar, then click on "Get started"
    Google Cloud Console - OAuth consent screen
  10. Input project's name, for example "n8n" and select your email, click "Next"
    Google Cloud Console - App information
  11. On the "Audience" step select "External", click "Next"
    Google Cloud Console - Audience
  12. On the "Contact information" write your email again, then proceed to "Finish" and click "Create"
    Google Cloud Console - Contact information and Finish
  13. Click on the "Audience" in the sidebar and scroll down to "Test users", click "Add users". Add your email and click "Save".
    Google Cloud Console - Add test user
  14. Click on the "Clients" in the sidebar, "Create client", choose Application type = "Web application".
    Google Cloud Console - Create Client, Web Application
  15. Scroll down to "Authorized JavaScript origins" and put there https://YOUR_N8N_DOMAIN. In "Authorized redirect URIs" put your domain append with the following path: /rest/oauth2-credential/callback (see screenshots). Click "Create".
    Google Cloud Console - Set up authorized JavaScript URLs
  16. Copy and paste to some safe place your Client ID and Client Secret. Do not show or pass them to anyone. Click "OK".
    Google Cloud Console - Copy and Save client id and client secret
  17. Click on "Data Access" in the sidebar, then on "Add or remove scopes".
    Google Cloud Console - Add or remove scopes
  18. Put in the Filter input "gmail.modify", click it and then mark the checkbox against "../auth/gmail.modify". Click "Update".
    Google Cloud Console - Add gmail.modify scope
  19. Scroll the page down, click "Save".
    Google Cloud Console - Save scopes
  20. That's it. We've finished with GCC, now let's move to N8N, create the credential and the workflow itself.

Step 2: Create credential in your N8N

  1. Please, check that you're using the same N8N url that you stated on the step 15 of previous section. If you don't have your own self hosted N8N, please check my manual.
  2. Open your N8N and move to "Credentials" section.
    N8N - Create Credential
  3. Search for "Gmail OAuth2 API", click "Continue"
    N8N - Gmail OAuth2 API
  4. Put your Client ID and Client Secret, then press "Save" button
    N8N - Fill in client id and secret
  5. IMPORTANT: there's a bug in N8N, so you have to Close this window and open it again before pressing "Sign in with Google" button
    N8N - Close before Signing in with Google
  6. Open credential again and press "Sign in with Google", click on your email
    N8N - Sign in with Google
  7. Press "Continue" (on the left)
    N8N - Sign in with Google
  8. Mark these checkboxes: "View your email messages when you interact with the add-on", "Read, compose, and send emails from your Gmail account"
    N8N - Approve Scopes
  9. Click "Continue" to see "Connection successful" screen
    N8N - Approve Scopes

Step 3: Create workflow with Gmail Trigger node

  1. If you don't have your own self hosted N8N, please check my manual.
  2. Open your N8N and move to "Workflows" section, click "Create workflow".
    N8N - Create Credential
  3. Give it a name, like "Gmail Trigger Workflow" (optional).
    N8N - Create Credential
  4. Click "Add first step", search for "gmail", select "Gmail" node, then click "On message received".
    N8N - Name your workflow
  5. Click "Back to canvas", then "Activate workflow"
    N8N - Add Gmail Trigger node
  6. Click "Execute workflow" to see success message.
    N8N - Workflow executed successfully
  7. Now, send test email from another email address, wait about a minute and check Executions tab.
    N8N - Send test email and check executions
  8. Double-click on Gmail node to see the text from the email you've sent.
    N8N - Check email text
  9. ✅ That's it! You've set up a gmail node that executes each time you receive a new email.

Next time we'll take a closer look at what could be done with the email after receiving. For example, you can trigger other workflows depending on keywords, or send attachment to your personal telegram account. Please, feel free to share your ideas or requests. Maybe I'll tasks yours for the next guide :)

If you've found this tutorial useful, you can buy me a coffee:





Contact

For questions or consultations, don't hesitate to contact me.

Signal: andyjam.27
Email: andy@isd-group.com
Threads: @andrewsergeyev
LinkedIn: andrew-sergyeyev
YouTube: @andrewsergeyev