Connection closed unexpectedly error during sending email via Send Email node with gmail credentials

I’m using a Send Email node in my workflow (with mockup data and settings for testing purpose) in local docker instance:

[
  {
    "createdAt": "2024-11-19T00:20:41.087Z",
    "updatedAt": "2024-11-19T15:15:47.000Z",
    "id": "K1t5FtYmnpO5Ah9e",
    "name": "Error Workflow",
    "active": false,
    "nodes": [
      {
        "parameters": {},
        "id": "96ea5c1d-858e-4bb9-b84d-64890d7aeb52",
        "name": "When clicking ‘Test workflow’",
        "type": "n8n-nodes-base.manualTrigger",
        "typeVersion": 1,
        "position": [500, 200]
      },
      {
        "parameters": {
          "fromEmail": "[email protected]",
          "toEmail": "[email protected]",
          "subject": "my message subject",
          "emailFormat": "text",
          "text": "my message text",
          "options": {}
        },
        "id": "71bafbe6-04bb-4eda-b33f-fa7bd3a00367",
        "name": "Send Email",
        "type": "n8n-nodes-base.emailSend",
        "typeVersion": 2.1,
        "position": [720, 200],
        "credentials": {
          "smtp": { "id": "fMmdwyvm62L1Fph9", "name": "SMTP account" }
        }
      }
    ],
    "connections": {
      "When clicking ‘Test workflow’": {
        "main": [[{ "node": "Send Email", "type": "main", "index": 0 }]]
      }
    },
    "settings": { "executionOrder": "v1" },
    "staticData": null,
    "meta": { "templateCredsSetupCompleted": true },
    "pinData": {},
    "versionId": "bf6ca440-c3f8-46fd-8f0d-26570b071d07",
    "triggerCount": 0,
    "tags": []
  }
]

Accordingly, I created a SMTP account credential with username and password (App Password that was generated in my Gmail account after enabling 2-step Verification), host smtp.gmail.com port 465 (all these data provided above):

[
  {
    "createdAt": "2024-11-19T00:26:01.681Z",
    "updatedAt": "2024-11-19T09:54:49.070Z",
    "id": "fMmdwyvm62L1Fph9",
    "name": "SMTP account",
    "data": {
      "user": "[email protected]",
      "password": "gmail-app-password",
      "host": "smtp.gmail.com",
      "hostName": "[email protected]"
    },
    "type": "smtp"
  }
]

and when I’m executing the flow - I’m getting error response: “Connection closed unexpectedly”

GMail-account [email protected] successfully sending emails in Thunderbird mail client with the same smtp server address and port (smtp.gmail.com + 465), and also I checked it inside the n8n docker container, using telnet smtp.gmail.com 465 - works without errors.

Also when this error occurs in borwser GUI, in docker console there’s a such output:

Connection closed unexpectedly
Error: Connection closed unexpectedly
    at SMTPConnection._onClose (/usr/local/lib/node_modules/n8n/node_modules/nodemailer/lib/smtp-connection/index.js:844:34)
    at TLSSocket.SMTPConnection._onSocketClose (/usr/local/lib/node_modules/n8n/node_modules/nodemailer/lib/smtp-connection/index.js:195:42)
    at Object.onceWrapper (node:events:634:26)
    at TLSSocket.emit (node:events:531:35)
    at TLSSocket.emit (node:domain:488:12)
    at node:net:339:12
    at TCP.done (node:_tls_wrap:648:7)

So what can be the reason and how to solve this problem?

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:

Hey @Sergii_Matsiupa , why are you using Send Email node with GMail account? Use dedicated Gmail node for that.