2

我有发送消息的用户界面。用户输入主题、消息正文、要发送的电子邮件、附加一些文件。提交后,我需要将消息作为 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 消息中发送。谢谢。

4

2 回答 2

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);    

我希望它有所帮助。

于 2014-10-18T10:47:46.290 回答
0

我认为你应该看看 Node.js 模块的世界......你将无法从浏览器客户端实际发送 MIME 邮件消息,因为没有提供 SMTP 支持。但是您可以通过 XHR 将预先格式化的消息发布到您的 Web 服务器,然后让 Web 服务器实际发送消息。

这看起来可以满足您的需求:
https ://www.npmjs.org/package/mailcomposer

即你可以准备一个 MIME 消息作为一个字符串

这个工具可能有助于在浏览器中使用 Node.js 模块:http:
//browserify.org/

于 2014-10-15T12:32:54.877 回答