Search code examples
javascriptemlsheetjs

How to attach a valid XLSX file in eml using JavaScript


I've tried the following multipart content-type. I will attach an excel file later using SheetJS. But right now I am unable to attach a valid blank excel file. Any help will be greatly appreciated.

  let text =
        'To: User <[email protected]>\n' +
        'Subject: TW Order\n' +
        'X-Unsent: 1\n' +
        'Content-Type: multipart/mixed; boundary=--boundary_text_string\n\n' +
        '----boundary_text_string\n' +
        //'Content-Type:  application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=demo.xlsx\n' +
        'Content-Type: application/octet-stream; name=demo.xlsx\n' +
        'Content-Disposition: attachment;\n\n' +
        '----boundary_text_string--';

Solution

  • So in order to attach an xlsx file to eml we have to do the following

     let text =
            'To: User <[email protected]>\n' +
            'Subject: TW Order\n' +
            'X-Unsent: 1\n' +
            'Content-Type: multipart/mixed; boundary=--boundary_text_string\n\n' +
            '----boundary_text_string\n' +
            'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;\n' +
            'Content-Transfer-Encoding: base64\n'
            'Content-Disposition: inline; filename=a.xlsx\n\n' +
            'base64 data goes here\n\n'
            '----boundary_text_string--';