Marak / node_mailer

## Project deprecated, see README
MIT License
387 stars 64 forks source link

Ability to include attachments #69

Open jdarling opened 12 years ago

jdarling commented 12 years ago

It would be great if you could attach files to the emails that are being sent. Looking at sample PHP code from ( http://webcheatsheet.com/PHP/send_email_text_html_attachment.php ) this might not be difficult to achieve. Will look into it more and post back what I find.

jdarling commented 12 years ago

Here is a start (the code to encode source stream or file into base64 chunk data):

var encodeStreamForEmail = function(source, callback){ var content64 = source.toString('base64'); var chunklen = 76; var endWith = '\r\n'; var contentEncoded = []; var i = 0, l = content64.length; for(; i < l; i+=chunklen){ contentEncoded.push(content64.substr(i, chunklen)); } callback(null, contentEncoded.join(endWith)); };

var encodeFileForEmail = function(sourceFileName, callback){ var fs = require('FS'); fs.readFile(sourceFileName, function(data){ encodeStreamForEmail(data, callback); }); };

Still have to look into header's, mime types, etc...

andris9 commented 12 years ago

I'm not sure if and how node_mailer handles attachments but Nodemailer which is beneath node_mailer used for the transport supports any kind of attachments (files, streams, strings)

echessa commented 12 years ago

I tried to use attachments as demonstrated in the https://github.com/andris9/Nodemailer example using this node_mailer(Marak's) but I got this error: Cannot call method 'replace' of undefined. Does anyone know how to include attachments using node_mailer. I chose node_mailer over Nodemailer because it supports use of templates so I'd prefer to send attachments with node_mailer