Lesson 66 min

How to Connect n8n to Gmail

Learn how to connect n8n to your Gmail account by setting up Google Cloud Platform credentials, enabling the Gmail API, and sending emails from your workflow.

How to Connect n8n to Gmail

To send and manage emails from your n8n workflows using Gmail, you need to configure credentials through the Google Cloud Platform. This tutorial provides a step-by-step guide on creating a Google Cloud project, setting up OAuth 2.0, and connecting your Gmail account to the n8n Gmail node.


Prerequisites

  • An n8n workflow (a manual trigger is fine for testing).
  • A Google Account to create a Google Cloud project and connect to Gmail.

Step 1: Create a Google Cloud Project

You'll need a Google Cloud project to manage the Gmail API and the necessary credentials.

  1. Navigate to the Google Cloud Console.
  2. Sign in with your Google account and accept the terms if you haven't already.
  3. Click the project selection dropdown in the top-left corner and select "New Project".
  4. Enter a project name, such as n8n-gmail-setup.
  5. Click "Create".
  6. After the project is created, ensure it is selected from the dropdown menu.

The consent screen informs users which application is requesting access to their data.

  1. Open the navigation menu (hamburger icon) and go to "APIs & Services" > "OAuth consent screen".
  2. Choose the "External" user type for your test application and click "Create".
  3. Provide the required details:
    • App name: n8n Gmail Integration
    • User support email: Your email address.
    • Developer contact information: Your email address.
  4. Click "Save and Continue" for the "Scopes" and "Optional info" sections.
  5. In the "Test users" step, click "+ Add Users".
  6. Enter the email address of the Gmail account you intend to connect. This is a critical step to authorize your test application.
  7. Click "Add", then "Save and Continue".
  8. Click "Back to Dashboard" on the summary page.

Step 3: Create OAuth 2.0 Credentials

These credentials (Client ID and Secret) will be used by n8n to authenticate.

  1. Go to "APIs & Services" > "Credentials".
  2. Click "+ Create Credentials" and choose "OAuth client ID".
  3. Set the "Application type" to "Web application".
  4. Provide a name, like n8n Gmail Client.
  5. In the "Authorized redirect URIs" section, you must add the redirect URL from n8n.
    • Open your n8n workflow and add a Gmail node.
    • In the "Credential" field, choose "Create New".
    • Copy the "OAuth Redirect URL" provided in the n8n credential modal.
    • Paste this URL back into the "Authorized redirect URIs" field in the Google Cloud Console.
  6. Click "Create". Your Client ID and Client Secret will be displayed. Keep this information handy.

Step 4: Configure the Gmail Node in n8n

Return to your n8n workflow to finalize the connection.

4.1 Create Gmail Credentials

  1. In the Gmail node's credential settings, copy the Client ID from Google Cloud and paste it into the "Client ID" field in n8n.
  2. Do the same for the Client Secret.
  3. Click "Save".

4.2 Authenticate Your Account

  1. A "Sign in with Google" button will now be visible. Click it.
  2. Select the Google account you previously added as a test user.
  3. A warning screen may appear stating that "Google hasn't verified this app." This is normal for apps in testing mode. Click "Continue".
  4. Grant the requested permissions for managing your email drafts and messages.
  5. Upon success, the window will close, and your n8n credential will be ready.

Step 5: Enable the Gmail API

The connection is authenticated, but the Gmail API must be enabled for your project.

  1. In the Gmail node, configure a simple operation, like Send Message. Fill in the recipient, subject, and body.
  2. When you execute the node, it will likely fail with an error: Gmail API has not been used in project ... or it is disabled.
  3. The error message contains a link. Copy and paste this link into a new browser tab.
  4. On the Gmail API page, click the "Enable" button.

Step 6: Send a Test Email

After enabling the API, go back to n8n and re-run the workflow.

  1. Click "Execute Node" on the Gmail node again.
  2. This time, the execution should be successful.

Check the recipient's inbox, and you will find the test email sent from your n8n workflow. You have now successfully connected n8n to Gmail and can start building powerful email automations.