我正在我的网站上创建一个带附件的 eml 文件。 我在这个链接中看到:eml with attachment 按照以下方式进行操作,但是在下载 eml 文件时它会打开一个附件。当我单击附件时,即使它的大小超过 0 个字节,附件也会打开为空。
const makeOutlookFile = () => {
const text = ` To: Demo-Recipient <[email protected]>
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();
};
我搜索了很多关于如何创建带有附件的 eml 文件,但所有答案或多或少都给出了这段代码