Centralized Solution for Multiple Gmail Accounts in n8n

Hi everyone,

I’ve developed a workflow in n8n that:

  1. Watches emails using a Gmail Trigger.
  2. Uses a Text Classifier to categorize emails (e.g., Leads, Qualified Leads, etc.).
  3. Adds labels to emails based on the classification.

This worked fine when I had just one Gmail account. However, I now need to add six more Gmail accounts, and I want to avoid creating six separate workflows.

I tried adding multiple Gmail Triggers in the same workflow and duplicating the logic for each account, but it quickly became unmanageable. Anytime I need to make a change, I would have to update everything for all accounts, which is time-consuming and error-prone.

Is there a way to:

  • Centralize the logic so I don’t have to duplicate it for each account?
  • Use dynamic inputs or parameters to handle multiple Gmail accounts within a single workflow?

Any guidance or best practices for handling this kind of scenario in n8n would be greatly appreciated!

Thanks in advance!

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Rohit_Gurav,

This looks like a similar question to this one here: Passing credentials as variables and this is the solution that’s being suggested:

There’s also a feature request to Allow expression for credential selection which might be relevant. Hope that helps :star:

Even if try this solution how do I set up trigger as I have 6 primary email account and they might receive e-mails simultaneously

This post is a few months old (and I’m new to n8n), so maybe this is a newer feature. Took me a while to find the answer; posting here, in case your research brings you here too.

I don’t think this will work for OAuth, since that flow is interactive, but for token-based auth, you can set an expression as the token value in a Credential.

Example:

{{ $json["your-access-token-field"] }}

You can ignore the message, “[ERROR: Referenced node doesn’t exist].” Once you’ve successfully run the step that collects the token, the expression will turn green if it can find the field and red if it can’t.

Shoutout to this workflow that taught me it’s possible:
https://n8n.io/workflows/2223-set-credentials-dynamically-using-expressions/

I’ve had successful tests with pulling the value from a form for the NASA api (from the demo workflow above) and from a webhook post for Slack. You can make Google app tokens here: https://myaccount.google.com/apppasswords.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.