Send an Attachment(PDF) using Send Email node

Hi there! I’ve been trying to send an attachment using the Send Email node but It doesn’t seem to work. I did get the file using the Http Request node and now passing the binary data to the Send email node but when I try to execute it, the email was sent but without the attachment. Any insight or suggestion to do to get around this? Thank You! Keep safe!

OK SO! It suddenly worked! i followed the code you’ve provided with sending multiple attachments! now the attachment is with the email!!! but! why is it that i needed to manually type “data” (propertyname) to the attachment field??? because when i try to go to “Add Expression” > “Current Node” > “Input Data” > “Binary” > “data” there are these “fileName”, “fileExtension”, “mimeType” in which when i try to click them it won’t show anything to the email i’ve sent, and that is why I’m surprised that it did send the attachment by me just trying to type “data” (propertyname from the http node)

my only problem now is, when i try to open the file from the email sent, it fails to load, saying that it is corrupted. you have any idea why? Is it because I did parse it wrongly?

Btw, I am accessing an Invoice file from woocommerce node. There is this key and value that I am using with the http node, and return the result as “file”

You have to type “data” that n8n knows:

  1. It should add an attachment
  2. Which data should be used as attachment (in this case it should use the data of the binary property with the name “data”)

The field expects the name of the binary property which contains the data that should be send. So it expects a string (text). When you add an expression you can create that property-name dynamically but you can not add the data directly because that is not how n8n works. Every node in n8n which uses binary data works the same way, it expects the name of the binary property it should use.

Expressions in n8n can not reference binary data. They only work with text and numbers. For that reason do you only get displayed the data which is “usable” like for example the file-name.

Why the file is corrupt I do not know. Can you display it correctly inside of n8n?

Here a basic example workflow downloading a PDF and then sending it via Email:

{
  "nodes": [
    {
      "parameters": {
        "fromEmail": "",
        "toEmail": "",
        "subject": "Test with attachment",
        "text": "With attachment",
        "attachments": "data",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        650,
        300
      ],
      "credentials": {
        "smtp": "zoho - n8n.io"
      }
    },
    {
      "parameters": {
        "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks @jan! I would try to further explore about this and hoping that I could figure something out :slight_smile:

Hi! so we’re able to make this work :slight_smile: apparently, we need to access the pdf file straight from where it is being stored on the server and now we can access it and send it successfully through the Send Email node

1 Like