Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "emailjs", | ||
"description": "send emails, html and attachments from node.js to any smtp server", | ||
"version": "0.1.5", | ||
"description": "send text/html emails and attachments from node.js to any smtp server", | ||
"version": "0.1.6", | ||
"author": "eleith", | ||
@@ -6,0 +6,0 @@ "contributors" : [ |
@@ -1,2 +0,2 @@ | ||
#v0.1.2 | ||
#v0.1.6 | ||
@@ -103,7 +103,7 @@ ### emailjs | ||
// headers is an object with the following keys ('from' and 'to' are required) | ||
// headers is an object ('from' and 'to' are required) | ||
// returns a Message object | ||
// you can actually pass any headers you want to send, the below are just the | ||
// most common ones you would want to use, from and to being required... | ||
// you can actually pass more message headers than listed, the below are just the | ||
// most common ones you would want to use | ||
@@ -120,3 +120,3 @@ headers = | ||
## Message.attach_alternative(html) | ||
## Message.attach_alternative(html, charset) | ||
@@ -126,2 +126,3 @@ // should only be called once | ||
html // string representing the html version of the email message | ||
charset // defaults to utf-8 if not passed | ||
@@ -128,0 +129,0 @@ ## Message.attach(path, mime_type, name) |
@@ -21,13 +21,23 @@ var stream = require('stream'); | ||
this.attachments = []; | ||
this.text = headers.text; | ||
this.html = null; | ||
this.header = {"message-id":"<" + (new Date()).getTime() + "." + process.pid + "@" + os.hostname() +">"}; | ||
this.content = "text/plain; charset=utf-8"; | ||
delete headers.text; | ||
for(var header in headers) | ||
{ | ||
// allow any headers the user wants to set?? | ||
// if(/cc|bcc|to|from|reply-to|sender|subject|date|message-id/i.test(header)) | ||
this.header[header.toLowerCase()] = headers[header]; | ||
// allow user to override default content-type to override charset or send a single non-text message | ||
if(/^content-type$/i.test(header)) | ||
{ | ||
this.content = headers[header]; | ||
} | ||
else if(header == 'text') | ||
{ | ||
this.text = headers[header]; | ||
} | ||
else | ||
{ | ||
// allow any headers the user wants to set?? | ||
// if(/cc|bcc|to|from|reply-to|sender|subject|date|message-id/i.test(header)) | ||
this.header[header.toLowerCase()] = headers[header]; | ||
} | ||
} | ||
@@ -45,5 +55,5 @@ }; | ||
attach_alternative: function(html) | ||
attach_alternative: function(html, charset) | ||
{ | ||
this.html = html; | ||
this.html = {message:html, charset:charset || "utf-8"}; | ||
return this; | ||
@@ -159,8 +169,9 @@ }, | ||
data = data.concat(["--", boundary, CRLF]); | ||
data = data.concat(["Content-Type:text/plain", CRLF, "Content-Transfer-Encoding: quoted-printable", CRLF, "Content-Disposition: inline", CRLF, CRLF]); | ||
data = data.concat(["Content-Type:", self.message.content, CRLF, "Content-Transfer-Encoding: 7bit", CRLF, "Content-Disposition: inline", CRLF, CRLF]); | ||
data = data.concat([self.message.text, CRLF, CRLF]); | ||
data = data.concat(["--", boundary, CRLF]); | ||
data = data.concat(["Content-Type:text/html", CRLF, "Content-Transfer-Encoding: base64", CRLF, "Content-Disposition: inline", CRLF, CRLF]); | ||
data = data.concat([(new Buffer(self.message.html)).toString("base64"), CRLF, CRLF]); | ||
data = data.concat(["Content-Type:text/html; charset=", self.message.html.charset, CRLF, "Content-Transfer-Encoding: base64", CRLF]); | ||
data = data.concat(["Content-Disposition: inline", CRLF, CRLF]); | ||
data = data.concat([(new Buffer(self.message.html.message)).toString("base64"), CRLF, CRLF]); | ||
@@ -237,2 +248,3 @@ data = data.concat(["--", boundary, "--", CRLF, CRLF]); | ||
{ | ||
self.emit("Content-Type:" + self.content + CRLF); | ||
self.emit('data', CRLF + self.message.text); | ||
@@ -239,0 +251,0 @@ self.emit('end'); |
42743
1376
138