Readme.md (2175B)
1 mime-js 2 ======= 3 4 Sometimes you need to create MIME message in browser. With *mime-js* you can create expected MIME message text. 5 6 Install 7 ------- 8 9 Run from terminal: 10 11 `npm install` 12 13 `gulp` 14 15 Sample Usage 16 ------------ 17 18 Mime object has two public methods: Mime.toMimeTxt() and Mime.toMimeObj(). See sample and its result. 19 20 21 ```javascript 22 var originalMail = { 23 "to": "email1@example.com", 24 "cc": "email2@example.com", 25 "subject": "Today is rainy", 26 "fromName": "John Smith", 27 "from": "john.smith@mail.com", 28 "body": "Sample body text", 29 "cids": [], 30 "attaches" : [] 31 }; 32 var mimeTxt = Mime.toMimeTxt(originalMail); 33 var mimeObj = Mime.toMimeObj(mimeTxt); 34 console.log(mimeTxt); 35 console.log(mimeObj); 36 37 ``` 38 39 **Result** 40 41 MimeTxt 42 ------- 43 44 ``` 45 MIME-Version: 1.0 46 Date: Sun, 10 May 2015 11:50:39 +0000 47 Message-ID: <i2ozrb4lgrgrpb9hp8wrf4n449xjemi@mail.your-domain.com> 48 Subject: =?UTF-8?B?VG9kYXkgaXMgcmFpbnk=?= 49 From: =?UTF-8?B?Sm9obiBTbWl0aA==?= <john.smith@mail.com> 50 To: email1@example.com 51 Cc: email2@example.com 52 Content-Type: multipart/mixed; boundary=qr7c8bjwkc81if6r9xpqmra8rrudi 53 54 --qr7c8bjwkc81if6r9xpqmra8rrudi 55 Content-Type: multipart/related; boundary=zh0eu0iqfdtv5cdiqigyhqinn1r79zfr 56 57 --zh0eu0iqfdtv5cdiqigyhqinn1r79zfr 58 Content-Type: multipart/alternative; boundary=56ksn4vpquissjorg32seupolt4eu3di 59 60 --56ksn4vpquissjorg32seupolt4eu3di 61 Content-Type: text/plain; charset=UTF-8 62 Content-Transfer-Encoding: base64 63 64 U2FtcGxlIGJvZHkgdGV4dA== 65 66 --56ksn4vpquissjorg32seupolt4eu3di 67 Content-Type: text/html; charset=UTF-8 68 Content-Transfer-Encoding: base64 69 70 PGRpdj5TYW1wbGUgYm9keSB0ZXh0PC9kaXY+ 71 72 --56ksn4vpquissjorg32seupolt4eu3di-- 73 --zh0eu0iqfdtv5cdiqigyhqinn1r79zfr-- 74 --qr7c8bjwkc81if6r9xpqmra8rrudi-- 75 ``` 76 77 78 MimeObj 79 ------- 80 81 ```javascript 82 {"html":"<div>Sample body text</div>","text":"Sample body text","attaches":[],"innerMsgs":[],"to":"email1@example.com","cc":"email2@example.com","from":"John Smith <john.smith@mail.com>","subject":"Today is rainy"} 83 ``` 84 85 ------------------------------------------------------------------ 86 87 **cids** - For inline images 88 **attaches** - any file in base64 format 89 90 ------------------------------------------------------------------