I'm generating a Word document using officegen that I then plan to attach to an email using Nodemailer (and Sendgrid).
officegen outputs a stream, but I'd prefer to pass that straight through to the attachment rather than saving the Word document locally and then 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 is a test email.'
attachments: [{ // stream as an attachment
filename: 'out.docx',
content: 'out.docx' // Ideally, I'd like this to be a stream through docx.generate()
}]
};
client.sendMail(email, function(err, info) {
if (err) {
console.log(err);
return res.send(400);
}
return res.send(200);
});