我有用户界面来发送消息。用户输入主题,消息正文,要发送的电子邮件,附加一些文件。提交后,我需要将消息作为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--
如何收集用户输入的信息作为MIME消息?我搜索了使用JavaScript在客户端构建MIME消息,但没有成功。如果存在附件,则需要将它们转换为base64字符串,然后在MIME消息中发送。谢谢。
最佳答案
我已经创建了一个JavaScript插件来在javascript中创建MIME消息。 https://github.com/ikr0m/mime-js。创建具有必要属性的mail
对象,然后调用createMimeMessage函数。它以javascript字符串形式返回准备好的MIME消息。
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);
希望对您有所帮助。
关于javascript - JavaScript:创建MIME消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17051315/