JavaScript:创建MIME消息

Ikr*_*rom 2 javascript mime message

我有用户界面发送消息.用户输入主题,邮件正文,发送电子邮件,附加一些文件.提交后我需要将消息作为MIME消息发送,如下所示:

From: John Doe <example@example.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="XXXXboundary text"

This is a multipart message in MIME format.

--XXXXboundary text 
Content-Type: text/plain

this is the body text

--XXXXboundary text 
Content-Type: text/plain;
Content-Disposition: attachment;
        filename="test.txt"

this is the attachment text

--XXXXboundary text--
Run Code Online (Sandbox Code Playgroud)

如何将用户输入的信息收集为MIME消息?我搜索使用JavaScript在客户端构建MIME消息但没有成功.如果存在附件,我需要将它们转换为base64字符串,然后在MIME消息中发送.谢谢.

Ikr*_*rom 8

我已经创建了一个javascript插件来在javascript中创建MIME消息.https://github.com/ikr0m/mime-js.创建mail具有必要属性的对象并调用createMimeMessage函数.它将准备好的MIME消息作为javascript字符串返回.

var mail = {  
    "to": "email1@example.com, email2@example.com",
    "subject": "Today is rainy",
    "fromName": "John Smith",
    "from": "john.smith@mail.com",
    "body": "Sample body text",
    "cids": [],
    "attaches" : []
}
var mimeMessage = createMimeMessage(mail);
console.log(mimeMessage);    
Run Code Online (Sandbox Code Playgroud)

我希望它有所帮助.