Code Node is not passing attachment through properly

Describe the problem/error/question

I’m trying to get emails filter by subject that contains the keyword “receipt” or “invoice” and then forward it to the relevant email that will be ingested by an accounting software.

The issue I noticed is that the code node somehow doesn’t pass the binary forward, so in the code node, on the left side I’m able to download the attachment, but on the right of it, i can’t seem to download it.

Some emails do have attachments (pdf as receipts), some receipts are just the email body (html) itself, hence the if node as I can’t seem to get it to use “data” or “attachment_0” on the attachment field name in the Email Node.

What is the error message (if any)?

So when it gets to the Send email (gmail), it’s throwing all sorts of error and one of them are “The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined (item 0)”.

Please share your workflow

Share the output returned by the last node

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined (item 0)

Information on your n8n setup

  • n8n version: 1.103.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main): manually clicking “Execute workflow” and then firing a message via telegram to the bot
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Sequoia 15.5

Like this?

1 Like

This works brilliantly! thank you!!

Didn’t know about the switch node, seems to be very effective.

“{{ Object.keys($binary).join(‘,’) }}” what is this do? attach more than 1 attachments to the same email?

Great!

You are correct, {{ Object.keys($binary).join(‘,’) }} is to make sure to include all passed binaries.

If this answered your question, kindly mark this as solved. Thank you!

Cheers!

quick one, I’ve been testing this for abit and i got the following error on the “Forward a message with attachment” node.

“this.getNodeParameter(…).trim is not a function (item 2)”, what does this error usually indicates?

Could be a bug, see

What’s the general approach? Wait for the fix or keep rerunning it? I’m just surprised that it works for the same email but stopped working for the same one when i replaced the email to the right email.

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