javascript - node.js Nodemailer array of objects to CSV file as attachment in email -
i'm sending email in node.js using nodemailer module. have array of objects i'm trying turn csv file , attach email. able send email, csv attachment doesn't populate correctly (showing blank). code looks similar following
var nodemailer = require('nodemailer'); // create reusable transporter object using smtp transport var transporter = nodemailer.createtransport({ service: 'gmail', auth: { user: 'gmail.user@gmail.com', pass: 'userpass' } }); var data = [{age:24,name:"bob"},{age:35,name:"andy"},...]; var mailoptions = { from: 'foo@blurdybloop.com', // sender address to: 'bar@blurdybloop.com', //receiver subject: 'hello', // subject line text: 'hello world', // plaintext body html: '<b>hello world</b>', // html body attachments: [ { filename: 'test.csv', content: data } }; // send mail defined transport object transporter.sendmail(mailoptions, function(error, info){ if(error){ return console.log(error); } console.log('message sent: ' + info.response); });
i'm guessing it's not able read array of objects , works string separated commas?
you should specify content
property string. nodemailer doesn't convert files itself. need convert data csv string before sending it. use module to-csv it.
Comments
Post a Comment