Error sending emails via SMTP

Hi,

I’m trying to get my first very simple workflow to work. I want to monitor an email inbox with the IMAP trigger task, filter the incoming emails by their subject, and in some cases send the contents of the email to another email address via SMTP. Any info on how to fix this issue would be much appreciated!

Best Regards, Fredrik

What is the error message (if any)?

In the very last step (sending via SMTP) an error window pops up with this text:
There was a problem executing the workflow:
"Converting circular structure to JSON → starting at object with constructor ‘Object’ — property ‘issuerCertificate’ closes the circle"

Please share the workflow

{
“nodes”: [
{
“parameters”: {
“format”: “resolved”,
“options”: {}
},
“name”: “IMAP Email”,
“type”: “n8n-nodes-base.emailReadImap”,
“typeVersion”: 1,
“position”: [
380,
500
],
“credentials”: {
“imap”: {
“id”: “7”,
“name”: “[email protected] IMAP”
}
}
},
{
“parameters”: {
“functionCode”: “// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\n\nconst validItems = [];\nfor (item of items) {\n if(item.json.subject.match(/^Your order \d{5} in our Brandshop$/g))\n {\n validItems.push(item);\n }\n}\n\nreturn validItems;”
},
“name”: “Function”,
“type”: “n8n-nodes-base.function”,
“typeVersion”: 1,
“position”: [
760,
520
]
},
{
“parameters”: {
“fromEmail”: “[email protected]”,
“toEmail”: “[email protected]”,
“subject”: “={{$node[“Function”].json[“subject”]}}”,
“text”: “={{$node[“Function”].json[“text”]}}”,
“html”: “={{$node[“Function”].json[“html”]}}”,
“options”: {}
},
“name”: “Send Email”,
“type”: “n8n-nodes-base.emailSend”,
“typeVersion”: 1,
“position”: [
1060,
540
],
“credentials”: {
“smtp”: {
“id”: “8”,
“name”: “[email protected] SMTP”
}
}
}
],
“connections”: {
“IMAP Email”: {
“main”: [
[
{
“node”: “Function”,
“type”: “main”,
“index”: 0
}
]
]
},
“Function”: {
“main”: [
[
{
“node”: “Send Email”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}

Share the output returned by the last node

As I’m not transforming the data, it is just je normal output of the imap trigger.

Information on your n8n setup

  • n8n version: 0.150.0
  • Database MySQL
  • Running n8n with the execution process own
  • Running n8n via Docker

I also just noticed that I have an error message regarding a database migration in the console when I start the docker container, could that be related to it?

(node:7) UnhandledPromiseRejectionWarning: TypeError: nodes.forEach is not a function
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:27:23
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:24:23
    at MigrationHelpers.runChunked (/usr/local/lib/node_modules/n8n/dist/src/databases/MigrationHelpers.js:15:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async UpdateWorkflowCredentials1630451444017.up (/usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:23:9)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:7) UnhandledPromiseRejectionWarning: TypeError: nodes.forEach is not a function
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:27:23
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:24:23
    at MigrationHelpers.runChunked (/usr/local/lib/node_modules/n8n/dist/src/databases/MigrationHelpers.js:15:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async UpdateWorkflowCredentials1630451444017.up (/usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:23:9)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:7) UnhandledPromiseRejectionWarning: TypeError: nodes.forEach is not a function
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:27:23
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:24:23
    at MigrationHelpers.runChunked (/usr/local/lib/node_modules/n8n/dist/src/databases/MigrationHelpers.js:15:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async UpdateWorkflowCredentials1630451444017.up (/usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:23:9)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:7) UnhandledPromiseRejectionWarning: TypeError: nodes.forEach is not a function
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:27:23
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:24:23
    at MigrationHelpers.runChunked (/usr/local/lib/node_modules/n8n/dist/src/databases/MigrationHelpers.js:15:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async UpdateWorkflowCredentials1630451444017.up (/usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:23:9)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:7) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined
    at /usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:90:24
    at Array.forEach (<anonymous>)
    at UpdateWorkflowCredentials1630451444017.up (/usr/local/lib/node_modules/n8n/dist/src/databases/mysqldb/migrations/1630451444017-UpdateWorkflowCredentials.js:87:29)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)

Hi @haarhoff-frs, first of all, welcome to the community! :tada:

I’m so sorry to hear you’re running into trouble - would you be able to share your workflow in a code block? Otherwise the forum software applies formatting to it (for example replacing the regular quotes with fancy quotes) and I can’t paste it into my own canvas.

You can do so through this button or by manually adding three backticks ``` before and below your JSON code:
image

Thanks so much!

Hi @MutedJam
Sorry for the reformatted code, here it is in a code block.
I have exchanged the email addresses, but the rest is directly copied over from n8n.

Additionally, this is the code of my function:

const validItems = [];
for (item of items) {
  if(item.json.subject.match(/^Your order \d{5} in ourBrandshop$/g))
  {
    validItems.push(item);
  }
}

return validItems;

So I tried this on my end but didn’t run into the problem you have described here:

So I am wondering if this might indeed be related to some upgrade/migration problem (or a different structure for my own email). Would this also happen for you on a fresh n8n instance using a fresh database? You could quickly spin one up on docker with this command, just make sure it uses a different port and volume than your existing one.

You are right, it seems to be a problem with the migrations for that particular instance. I started a new one as you suggested where I imported the workflow, and it immediately worked.
So I guess I’ll have to drop the database, create a new container, recreate the credentials and reimport the workflows.
Thanks a lot for your help, it is much appreciated! :slight_smile:

1 Like

Well, I didn’t really do much here and this shouldn’t have been necessary in the first place :see_no_evil:. So I am really sorry this happened.

However, if the new instance is working for you it’s probably the easiest way and more time efficient than figuring out what might have gone wrong during a previous migration. You can export (and import) credentials and workflows quite easily through the CLI (you would need to run the commands inside your container):

Either way, its always good to make sure that its not just due to my incompetence, so thanks again.
There weren’t a lot of workflows, so I was able to quickly reimport them and the credentials. Everything seems to be working properly :slight_smile:

2 Likes