My Excel attachment arrives as a .dat file

Describe the problem/error/question

I’m scraping Purchase Order line items from an email and creating an Excel spreadsheet to send out as an attachment. When I get the email the attachment is a .dat file instead of a .xls file and opening the .dat file in Notepad++ it looks like binary but it’s actually a zip file.
image

What is the error message (if any)?

No error generated.

Please share your workflow

{
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d6bd811c736796576ede335615dd3f4400481cb03c3c930ae298eebd4b232405"
  },
  "nodes": [
    {
      "parameters": {
        "postProcessAction": "nothing",
        "options": {
          "customEmailConfig": " [ \"UNSEEN\", [\"SUBJECT\", \"Purchase Order #\"] ]",
          "forceReconnect": 15
        }
      },
      "id": "65fee90b-674b-4d2e-903e-320adc706ccb",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [
        340,
        200
      ],
      "credentials": {
        "imap": {
          "id": "k9mfvmllkj094lDG4",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "subject": "={{ $('Email Trigger (IMAP)').item.json.subject.match(/Purchase Order #[0-9]*/)[0] }}",
        "emailFormat": "text",
        "text": "={{ $('Email Trigger (IMAP)').item.json.subject.match(/Purchase Order #[0-9]*/)[0] }}",
        "options": {
          "appendAttribution": false,
          "attachments": "={{ $node[\"Convert to CSV\"].parameter[\"binaryPropertyName\"] }}",
          "bccEmail": "[email protected]"
        }
      },
      "id": "bb4f53b4-4c78-4b68-993f-3c38f060e691",
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1340,
        200
      ],
      "credentials": {
        "smtp": {
          "id": "LIGHtbulbOBFuscated",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "operation": "xlsx",
        "options": {
          "fileName": "={{ $('Scrape Data').item.json[\"subject\"] }}"
        }
      },
      "id": "c4bd2a02-63b1-4361-9101-33cc072c7226",
      "name": "Convert to CSV",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        1140,
        200
      ]
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "dataPropertyName": "textHtml",
        "extractionValues": {
          "values": [
            {
              "key": "table",
              "cssSelector": "#order_lines tbody tr",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "id": "af4aeb0b-07bd-4ba5-9737-fbfb97bfcdff",
      "name": "HTML",
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        540,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "csv",
        "options": {}
      },
      "id": "5ed0442c-e30c-401f-b57b-a0d4e6c664ef",
      "name": "Split Out Data",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        940,
        200
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Init vars\nlet i = 0, line = \"\", ar = [];\n\nvar rowLength = $json.table.length;\nfor (i = 0; i < rowLength; i++){\n  line = $json.table[i].split('\\n\\n'); \n  ar.push([line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]);\n}\n\n// Save the line items\n$json.csv = ar;\n\n// Save subject line\n$json.subject = $('Email Trigger (IMAP)').item.json.subject.match(/Purchase Order #[0-9]*/)[0];\n\n// Done\nreturn $json;"
      },
      "id": "a4157ecd-d03c-4c64-a77a-0d41703c5a71",
      "name": "Scrape Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        200
      ]
    }
  ],
  "connections": {
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to CSV": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML": {
      "main": [
        [
          {
            "node": "Scrape Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Data": {
      "main": [
        [
          {
            "node": "Convert to CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Data": {
      "main": [
        [
          {
            "node": "Split Out Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {}
}```

## Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->

## Information on your n8n setup
- **n8n version:** 1.42.1
- **Database (default: SQLite):** Postgres
- **n8n EXECUTIONS_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** npm?
- **Operating system:** Linux

I also have a 2nd issue where a lot of the times when the Email node catches a matching email the textHtml field is empty where there should be the Purchase Order data. It’s like the email hasn’t fully arrived yet before the Email node detects it and starts processing before the receipt is complete. Is there a delay I can put in the “Options->Custom Email Rules” field to make sure it has fully arrived and been saved?

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