mime-js
mime-js copied to clipboard
Create MIME message in javascript
mime-js
Sometimes you need to create MIME message in browser. With mime-js you can create expected MIME message text.
Install
Run from terminal:
npm install
gulp
Sample Usage
Mime object has two public methods: Mime.toMimeTxt() and Mime.toMimeObj(). See sample and its result.
var originalMail = {
"to": "[email protected]",
"cc": "[email protected]",
"subject": "Today is rainy",
"fromName": "John Smith",
"from": "[email protected]",
"body": "Sample body text",
"cids": [],
"attaches" : []
};
var mimeTxt = Mime.toMimeTxt(originalMail);
var mimeObj = Mime.toMimeObj(mimeTxt);
console.log(mimeTxt);
console.log(mimeObj);
Result
MimeTxt
MIME-Version: 1.0
Date: Sun, 10 May 2015 11:50:39 +0000
Message-ID: <[email protected]>
Subject: =?UTF-8?B?VG9kYXkgaXMgcmFpbnk=?=
From: =?UTF-8?B?Sm9obiBTbWl0aA==?= <[email protected]>
To: [email protected]
Cc: [email protected]
Content-Type: multipart/mixed; boundary=qr7c8bjwkc81if6r9xpqmra8rrudi
--qr7c8bjwkc81if6r9xpqmra8rrudi
Content-Type: multipart/related; boundary=zh0eu0iqfdtv5cdiqigyhqinn1r79zfr
--zh0eu0iqfdtv5cdiqigyhqinn1r79zfr
Content-Type: multipart/alternative; boundary=56ksn4vpquissjorg32seupolt4eu3di
--56ksn4vpquissjorg32seupolt4eu3di
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
U2FtcGxlIGJvZHkgdGV4dA==
--56ksn4vpquissjorg32seupolt4eu3di
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64
PGRpdj5TYW1wbGUgYm9keSB0ZXh0PC9kaXY+
--56ksn4vpquissjorg32seupolt4eu3di--
--zh0eu0iqfdtv5cdiqigyhqinn1r79zfr--
--qr7c8bjwkc81if6r9xpqmra8rrudi--
MimeObj
{"html":"<div>Sample body text</div>","text":"Sample body text","attaches":[],"innerMsgs":[],"to":"[email protected]","cc":"[email protected]","from":"John Smith <[email protected]>","subject":"Today is rainy"}
cids - For inline images
attaches - any file in base64 format