GMail service account

I am trying to send an email via gmail using a service account. I have enabled the API and enabled domain wide delegation. When setting up the node and the service account within n8n the connection tested successfully, but when I test the actual now I get the following error message:

{
  "errorMessage": "Bad request - please check your parameters (item 0)",
  "errorDescription": "Precondition check failed.",
  "errorDetails": {
    "rawErrorMessage": [
      "400 - {\"error\":{\"code\":400,\"message\":\"Precondition check failed.\",\"errors\":[{\"message\":\"Precondition check failed.\",\"domain\":\"global\",\"reason\":\"failedPrecondition\"}],\"status\":\"FAILED_PRECONDITION\"}}"
    ]
  },
  "n8nDetails": {
    "nodeName": "Gmail",
    "nodeType": "n8n-nodes-base.gmail",
    "nodeVersion": 2.1,
    "resource": "message",
    "operation": "send",
    "itemIndex": 0,
    "time": "8/31/2024, 8:17:43 PM",
    "n8nVersion": "1.56.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeOperationError: Bad request - please check your parameters (item 0)",
      "    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Google/Gmail/v2/GmailV2.node.js:549:23)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:728:19)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:673:51",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1104:20"
    ]
  }
}

I also should add that the workflow works fine if I use OAuth and a “regular” Gmail account.

Any help with this would be greatly appreciated!

1 Like

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:

n8n version is
1.56.2 (Self Hosted)
hosted on vps running ubuntu 22 or 24 I forget

Hi @Ramon_Tomzer,

Welcome to the community :tada:

Judging by the error message from Google — Precondition check failed , it seems like you haven’t configured domain-wide delegation correctly or have done that and forgot to include the user on the domain.

If you have configured it, it might take up to 24 hours for it to work:

Note: It usually takes a few minutes for impersonation access to be granted after the client ID was added, but in some cases, it might take up to 24 hours to propagate to all users of your Google Account. (Usa OAuth 2.0 para aplicaciones de servidor a servidor  |  Authorization  |  Google for Developers)

See a similar issue posted here: php - Getting Precondition check failed - when using gmail api with a service account - Stack Overflow

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