Saturday 15 January 2011

node.js - Node: Using a passthrough stream to Nodemailer -



node.js - Node: Using a passthrough stream to Nodemailer -

i'm generating word document using officegen plan attach email using nodemailer (and sendgrid).

officegen outputs stream, i'd prefer pass straight through attachment rather saving word document locally , attaching it.

// generates output file docx.generate(fs.createwritestream ('out.docx')); var client = nodemailer.createtransport(sgtransport(options)); var email = { from: 'email@here', to: user.email, subject: 'test email send', text: 'hi!\n\n' + 'this test email.' attachments: [{ // stream attachment filename: 'out.docx', content: 'out.docx' // ideally, i'd stream through docx.generate() }] }; client.sendmail(email, function(err, info) { if (err) { console.log(err); homecoming res.send(400); } homecoming res.send(200); });

you can pass stream object straight content. officegen doesn't seem back upwards pipeing, need passthrough stream handle this

var passthrough = require('stream').passthrough; var docstream = new passthrough(); docx.generate(docstream); ... var attachments = [{ // stream attachment filename: 'out.docx', content: docstream }];

node.js stream sendgrid nodemailer

No comments:

Post a Comment