I'm creating an eml file on my website with an attachment. I saw in this link: eml with attachment to do it in the following way, but while downloading the eml file it opens with an attachment. When I click the attachment the attachment just opens empty even though its size is more than 0 bytes.
const makeOutlookFile = () => {
const text = ` To: Demo-Recipient <demo@demo.example.com>
Subject: EML with attachments
X-Unsent: 1
Content-Type: multipart/mixed; boundary=boundary_text_string
--boundary_text_string
Content-Type: text/html; charset=UTF-8
<html>
<body>
<p>Example</p>
</body>
</html>
--boundary_text_string
Content-Type: application/octet-stream; name=demo.log
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="demo.log"
aGVsbG8gd29ybGQ=
--boundary_text_string--`;
let textFile = null;
var data = new Blob([text], { type: 'message/rfc822' });
textFile = window.URL.createObjectURL(data);
let link = document.createElement("a");
link.href = textFile;
link.target = "_blank";
link.download = "";
document.body.appendChild(link);
link.click();
link.remove();
};
I searched a lot about how to create an eml file with an attachment but all the answers give this code more or less