Problem forwarding attachements received by IMAP with Send Email

Hello,

I have problems forwarding attachments with the Send Email node. Here’s what I try to do:

  • I receive emails with IMAP Emails (works :heavy_check_mark:)
  • I extract, transform, enrich data from the email body via Function and HTTP Request nodes (works :heavy_check_mark:)
  • I create and send an email using the results of that transformation for email content (works :heavy_check_mark:, new mail with additional information arrives in my post box)

However, now I want to add attachments of the original email to the mail that I send. But I cannot figure out how and I cannot make sense of the examples I find in this forum.

I tried and add a reference in the attachments field of Send Email, like {{$node[“IMAP Email”].binary.attachment_0}} or {{$node[“IMAP Email”].binary}} but no attachment is sent. I think I understood that this has to do with the reference somehow pointing to the parameters only and not the data. But how to I access the data? Any hint is highly appreciated.

Thanks!

Hey @Steffen,

Welcome to the community :sparkling_heart:

In your workflow do you change the Binary Property? To help you better understand, in your IMAP node the value of the Binary Property is attachment_0. Throughout the workflow if you don’t change the value, you can add attachment_0 in the Send Email node.

If you can share the workflow, we can take a close look.
(Check out this to learn how you can share the workflow: How can I contribute? | Docs)

Thanks for your quick answer. Hm, that’s what I tried but I guess there’s something I was missing.

Here’s the code:

The problem is that the binary data gets “lost” in the second HTTP Request node (“Testing Tools”) as it replaces the data. So what you would have to do is to merge it back in again.

You can do that with a Merge node set to “Merge By Index” like this:
Screenshot from 2021-07-16 17-30-36

In your case you have to add the Merge Node before the “Send Email” node with the second input connected to the first node (“IMAP Email”).

Here the above example worfklow:

Click to expand! ```json { "nodes": [ { "parameters": { "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test-Logo.svg/783px-Test-Logo.svg.png", "responseFormat": "file", "options": {} }, "name": "HTTP Request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ 450, 700 ] }, { "parameters": { "url": "http://example.com", "responseFormat": "string", "options": {} }, "name": "HTTP Request1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ 700, 700 ] }, { "parameters": { "mode": "mergeByIndex" }, "name": "Merge", "type": "n8n-nodes-base.merge", "typeVersion": 1, "position": [ 900, 900 ] } ], "connections": { "HTTP Request": { "main": [ [ { "node": "HTTP Request1", "type": "main", "index": 0 }, { "node": "Merge", "type": "main", "index": 1 } ] ] }, "HTTP Request1": { "main": [ [ { "node": "Merge", "type": "main", "index": 0 } ] ] } } } ```
1 Like

Nice! That solved my problem. I’m slowly getting the idea of how the data flows. Thanks a lot.

You are welcome. That is great to hear!

Have fun!