Function Node ERROR: No data got returned

I’m trying to optimise a workflow by including all of the logic in one Function Node, and therefore reducing the amount of times data has to be transferred between nodes. The main challenge was to covert Buffer data to Base64 encoded text.

I’ve worked out the Javascript code in VS Code, as follows:

let data = 'Return-path: <[email protected]>\nEnvelope-to: [email protected]\nDelivery-date: Sat, 05 Mar 2022 11:25:50 +0100\nReceived: from antispam2.mailplatform.eu ([2a04:8400:1:1::82])\n\tby mx2.mailplatform.eu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n\t(Exim 4.89)\n\t(envelope-from <[email protected]>)\n\tid 1nQRbh-0005GN-Un\n\tfor [email protected]; Sat, 05 Mar 2022 11:25:49 +0100\nReceived: from smtp5.mailplatform.eu ([185.40.97.8])\n\tby antispam2.mailplatform.eu with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256)\n\t(Exim 4.92)\n\t(envelope-from <[email protected]>)\n\tid 1nQRbe-0003AP-35\n\tfor [email protected]; Sat, 05 Mar 2022 11:25:49 +0100\nReceived: from 89-220-243-40.cable.dynamic.v4.ziggo.nl ([89.220.243.40]:49704 helo=smtpclient.apple)\n\tby smtp5.mailplatform.eu with esmtpsa  (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384\n\t(Exim 4.94.2)\n\t(envelope-from <[email protected]>)\n\tid 1nQRbe-000ekw-Hi\n\tfor [email protected]; Sat, 05 Mar 2022 11:25:45 +0100\nFrom: Dick <[email protected]>\nContent-Type: multipart\/alternative;\n\tboundary=\"Apple-Mail=_7CA4E961-9D1C-4EB7-AF0B-5524837E0A8C\"\nMime-Version: 1.0 (Mac OS X Mail 14.0 \\(3654.120.0.1.13\\))\nSubject: Testbericht voor n8n IMAP Email test\nMessage-Id: <[email protected]>\nDate: Sat, 5 Mar 2022 11:25:45 +0100\nTo: ecOrganizer BV <[email protected]>\nX-Mailer: Apple Mail (2.3654.120.0.1.13)\nReceived-SPF: pass (antispam2.mailplatform.eu: domain of ecxs.com designates 185.40.97.8 as permitted sender) client-ip=185.40.97.8; [email protected]; helo=smtp5.mailplatform.eu;\nX-SPF-Result: antispam2.mailplatform.eu: domain of ecxs.com designates 185.40.97.8 as permitted sender\nAuthentication-Results:  mailplatform.eu; spf=pass [email protected]\nX-SpamExperts-Class: ham\nX-SpamExperts-Evidence: Combined (0.14)\nX-Recommended-Action: accept\nX-Filter-ID: Mvzo4OR0dZXEDF\/gcnlw0bPV5764nXhv3pemVwzTVxOpSDasLI4SayDByyq9LIhV5q4jwaaWbCnT\n ctGzvQdTcUTNWdUk1Ol2OGx3IfrIJKywOmJyM1qr8uRnWBrbSAGDOQL1omT7S5\/x5Ibs69DcWIe8\n 8DhweqLx+xkR17qNHWMcBeuYPTH2AW5xUAT1C6EUeJpLxjaPHE1A\/OyZ+V+dxIPAgTtUp75uqlx0\n KezvZHU5nMrXCZpHjRP45O8eXA8St0KEs70OpJjFVF4iozgmEXQWi\/GAIHUNvqguJF1SA3ebfi76\n x+cAUmmNUoAEMHCbkPGM0gjRUiKLIDZN8BJwLXS5\/AB7OvPoiYN5XSEtDeJgk7\/I\/qRgO6rjKF\/t\n sk5xeKrbM9pblw4eKX\/T\/ztTNFpoyyH3213OCh\/Rn5ZZaImNjbXyZQJjwfl3lrh3+hNjlAWS88ME\n LcLoZFvkEawbqW8iewDDrbWg2t0GJH5E8fCiNaUmmFtv0ANUkj\/5aPeC0XAP8bsl+oJwA2fuXfo5\n cSl92iIMzvv5PAqEZHLdiOrz9\/XvW3ZbEHtSV5axGVKWKP9pWZyqSwiZS\/khPlqY4iQyb8lfZgBK\n XlDsYzYcI4B5+qQPT+n13sb\/5zpGduInjTC\/WGDpgzBnymVTRpk1lhhJWplVyfs19vCIUElc8Mem\n QGcyWBwu5cNh8dHPo0uikTGwQJL8ub+29P3fYVm+St993UhCz4P\/Qx+6mqWYqOMHSxT5lcpEl+Ut\n zPVSSm+xCSFSPpSMzSg1f\/gQfDJmSkIZdaAEAFiV+dWI1ki92sopxlfAmGNmu\/swehNq5tJfHHAS\n JNUmoOHSoqgqxfHmWSIBY+0F\/5tTMynUEBVgFh5qsV1mrkODtOX+52ZPPE63akeYr4hl5QPcYJDE\n LOzCpQa\/BGzmHf7SOfvPvvzDOeZG8eF2FOkheV7u6AxN9z8mises2YcOVNcJU11zQvrIDgkhUj6U\n jM0oNX\/4EHwyZkpV6Z0Tqr5Npzk11xLHRc6p\nX-Report-Abuse-To: [email protected]\n\n\n--Apple-Mail=_7CA4E961-9D1C-4EB7-AF0B-5524837E0A8C\nContent-Transfer-Encoding: 7bit\nContent-Type: text\/plain;\n\tcharset=us-ascii\n\ntest\n\ngroetjes - Dick Honing\n\nhttp:\/\/www.ecorganizer.nl - ecOrganizer CRM & ERP Software\n\n\n--Apple-Mail=_7CA4E961-9D1C-4EB7-AF0B-5524837E0A8C\nContent-Type: multipart\/related;\n\ttype=\"text\/html\";\n\tboundary=\"Apple-Mail=_9194C1ED-A8B2-45C7-9959-BFA1672DA6D2\"\n\n\n--Apple-Mail=_9194C1ED-A8B2-45C7-9959-BFA1672DA6D2\nContent-Transfer-Encoding: quoted-printable\nContent-Type: text\/html;\n\tcharset=us-ascii\n\n<html><head><meta http-equiv=3D\"Content-Type\" content=3D\"text\/html; =\ncharset=3Dus-ascii\"><\/head><body style=3D\"word-wrap: break-word; =\n-webkit-nbsp-mode: space; line-break: after-white-space;\" class=3D\"\"><div =\nclass=3D\"\"><div style=3D\"margin: 0px;\" class=3D\"\"><font face=3D\"Helvetica\"=\n size=3D\"3\" color=3D\"#000000\" style=3D\"font: 12.0px Helvetica; color: =\n#000000\" class=3D\"\">test<\/font><\/div><div style=3D\"margin: 0px; =\nfont-style: normal; font-variant-caps: normal; font-weight: normal; =\nfont-stretch: normal; font-size: 12px; line-height: normal; font-family: =\nHelvetica; color: rgb(0, 0, 0); min-height: 12px;\" class=3D\"\"><br =\nclass=3D\"\"><\/div><div style=3D\"margin: 0px;\" class=3D\"\"><font =\nface=3D\"Helvetica\" size=3D\"3\" color=3D\"#000000\" style=3D\"font: 12.0px =\nHelvetica; color: #000000\" class=3D\"\">groetjes - Dick =\nHoning<\/font><\/div><div style=3D\"margin: 0px; font-style: normal; =\nfont-variant-caps: normal; font-weight: normal; font-stretch: normal; =\nfont-size: 12px; line-height: normal; font-family: Helvetica; color: =\nrgb(0, 0, 0); min-height: 12px;\" class=3D\"\"><br class=3D\"\"><\/div><div =\nstyle=3D\"margin: 0px;\" class=3D\"\"><font face=3D\"Helvetica\" size=3D\"3\" =\ncolor=3D\"#000000\" style=3D\"font: 12.0px Helvetica; color: #000000\" =\nclass=3D\"\"><a href=3D\"http:\/\/www.ecorganizer.nl\" =\nclass=3D\"\">http:\/\/www.ecorganizer.nl<\/a> - ecOrganizer CRM &amp; ERP =\nSoftware<\/font><\/div><div style=3D\"margin: 0px; font-style: normal; =\nfont-variant-caps: normal; font-weight: normal; font-stretch: normal; =\nfont-size: 12px; line-height: normal; font-family: Helvetica; color: =\nrgb(0, 0, 0); min-height: 12px;\" class=3D\"\"><br class=3D\"\"><img =\napple-inline=3D\"yes\" id=3D\"A9B6E8A5-150D-446C-B4E3-18F382D1F0A4\" =\nsrc=3D\"cid:B2EC6BA3-7868-46D6-9B42-679CA6E56D7B\" class=3D\"\"><img =\napple-inline=3D\"yes\" id=3D\"23EA79E9-BBAB-4CCF-913B-87BFBBCA5F9F\" =\nsrc=3D\"cid:A13BB040-E461-4709-856A-775A6FC1B995\" =\nclass=3D\"\"><\/div><\/div><\/body><\/html>=\n\n--Apple-Mail=_9194C1ED-A8B2-45C7-9959-BFA1672DA6D2\nContent-Transfer-Encoding: base64\nContent-Disposition: inline;\n\tfilename=red.png\nContent-Type: image\/png;\n\tx-unix-mode=0666;\n\tname=\"red.png\"\nContent-Id: <B2EC6BA3-7868-46D6-9B42-679CA6E56D7B>\n\niVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABJ2lDQ1BrQ0dDb2xvclNwYWNlQWRv\nYmVSR0IxOTk4AAAokWNgYFJILCjIYRJgYMjNKykKcndSiIiMUmB\/xsDEIMjAzsDHIJ2YXFzgGBDg\nwwAEMBoVfLvGwAiiL+uCzMKUxwu4UlKLk4H0HyDOTi4oKmFgYMwAspXLSwpA7B4gWyQpG8xeAGIX\nAR0IZG8BsdMh7BNgNRD2HbCakCBnIPsDkM2XBGYzgeziS4ewBUBsqL0gIOiYkp+UqgDyvYahpaWF\nJol+IAhKUitKQLRzfkFlUWZ6RomCIzCkUhU885L1dBSMDIyMGBhA4Q5R\/TkQHJ6MYmcQYgiAEJsj\nwcDgv5SBgeUPQsykl4FhgQ4DA\/9UhJiaIQODgD4Dw745yaVFZVBjGJmMGRgI8QHuq0o9X4r8vwAA\nADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAA\nAQAAAADa6r\/EAAAADUlEQVQIHWPI7DX9DwAEuQIrFqrAyQAAAABJRU5ErkJggg==\n--Apple-Mail=_9194C1ED-A8B2-45C7-9959-BFA1672DA6D2\nContent-Transfer-Encoding: base64\nContent-Disposition: inline;\n\tfilename=green.png\nContent-Type: image\/png;\n\tx-unix-mode=0666;\n\tname=\"green.png\"\nContent-Id: <A13BB040-E461-4709-856A-775A6FC1B995>\n\niVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABJ2lDQ1BrQ0dDb2xvclNwYWNlQWRv\nYmVSR0IxOTk4AAAokWNgYFJILCjIYRJgYMjNKykKcndSiIiMUmB\/xsDEIMjAzsDHoJ6YXFzgGBDg\nwwAEMBoVfLvGwAiiL+uCzMKUxwu4UlKLk4H0HyDOTi4oKmFgYMwAspXLSwpA7B4gWyQpG8xeAGIX\nAR0IZG8BsdMh7BNgNRD2HbCakCBnIPsDkM2XBGYzgeziS4ewBUBsqL0gIOiYkp+UqgDyvYahpaWF\nJol+IAhKUitKQLRzfkFlUWZ6RomCIzCkUhU885L1dBSMDIyMGBhA4Q5R\/TkQHJ6MYmcQYgiAEJsj\nwcDgv5SBgeUPQsykl4FhgQ4DA\/9UhJiaIQODgD4Dw745yaVFZVBjGJmMGRgI8QEGlkpJgCIHvgAA\nADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAA\nAQAAAADa6r\/EAAAADUlEQVQIHWNQd\/v5HwAEZAJmmZ889AAAAABJRU5ErkJggg==\n--Apple-Mail=_9194C1ED-A8B2-45C7-9959-BFA1672DA6D2--\n\n--Apple-Mail=_7CA4E961-9D1C-4EB7-AF0B-5524837E0A8C--\n';

const results = [];

const simpleParser = require('mailparser').simpleParser;

simpleParser(data, '')
    .then(parsed => {
        items = parsed;

        let att = (items.attachments).length

        results.push({
            'From': items.from.value[0].address,
            'To': items.to.value[0].address,
            'Subject': items.subject,
            'Text': items.text,
            'HTML': items.html,
            'messageId': items.messageId,
            'Date': items.date
        });

        for (att in items.attachments) {

        results.push({
            attachement: Buffer.from(items.attachments[(att)].content).toString('base64'),
            filename: items.attachments[(att)].filename
        });

        }

        console.log (JSON.stringify(results));

    })
    .catch(err => { });

I then moved this logic into a Function Node, but I can’t seem to get it to work. I’m probably overlooking something simple, but currently, I can’t seem to see the forest for the trees.

Anybody any ideas on what I might be doing wrong and how to fix this?

This is my test workflow:

Please note that in order to make this work, you need mailparser …

NODE_FUNCTION_ALLOW_EXTERNAL=mailparser

Thanks in advance.

1 Like

I’ve already go it … promise does not seem to work, but await does …

let data = item;
const results = [];

const simpleParser = require('mailparser').simpleParser;
let parsed = await simpleParser(data, 'skipImageLinks');

let items = parsed;

let att = (items.attachments).length

results.push({
  'From': items.from.value[0].address,
  'To': items.to.value[0].address,
  'Subject': items.subject,
  'Text': items.text,
  'HTML': items.html,
  'messageId': items.messageId,
  'Date': items.date
});

for (att in items.attachments) {

results.push({
  attachement: Buffer.from(items.attachments[(att)].content).toString('base64'),
  filename: items.attachments[(att)].filename
});

}
        
return results;

BTW: I brought the processing time down by 25%, so I’m now concluding that most of the work actually takes place in the simpleParser (function) node and the transfer of data between nodes is actually not the biggest bottle neck … as long as you set Save execution progress in Settings to Default - No

3 Likes