node.js - How to send PDF file as an attachment in nodejs? -


i trying send pdf file attachment user when opening file error coming

"failed load pdf document."

i using node mailer send emails.

i not getting problem it.

please help!

here code:-

router.get('/file',function(req, res){      var fromname = "ikshit";      var mailoptions={          to: 'useremailid@gmail.com',          subject: 'test',          from: "email@gmail.com",          headers: {              "x-laziness-level": 1000,              "charset" : 'utf-8'          },          attachments: [               {                            raw: 'content-type: application/pdf; charset=utf-8;\r\n' +                   'content-disposition: attachment;filename=text.pdf;\r\n' +                   '\r\n' +                   'hello world!'          }      ],          html: 'text'               }      var transporter = nodemailer.createtransport({          service: 'gmail',          auth: {              user: 'email@gmail.com',               pass: 'password'           }      });      transporter.sendmail(mailoptions, function(error, response){          if(error){             return res.send(err);          }          else{              res.send({                  state:'success',                  message:"send"              });          }      });  })

try way...

var mailoptions = {   from: 'foo@bar.com'.   to: 'bar@foo.com',   subject: 'an attached file',   text: 'check out attached pdf file',   attachments: [{     filename: '<filename>',     path: '<pdf file absolute path>'     contenttype: 'application/pdf'   }]};  transporter.sendmail(mailoptions, function (err, info) {      if(err){        console.error(err);        res.send(err);      }      else{        console.log(info);        res.send(info);      }   } ); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -