Problem in excel email attachment


#1

Hi,
I am using Email.send() for sending excel file with attachments. But getting unable to open attachment in email ->

Email.send({
            to: email,
            from: "xxx@gmail.com",
            subject: "Report ",
            text:'Text',
            attachments: [
              {
                  filename: "report.xlsx",
                  contents: file,
                  encoding: 'binary',
                  contentType: 'application/octet-stream',
                  contentTransferEncoding: 'base64'
              }
            ]
          });

Where as in mailcomposer with nodemailer, it works perfectly. ->

var nodemailer = Meteor.npmRequire("nodemailer");
var transporter = nodemailer.createTransport([smtp]);
        var cid_value = Date.now() + '.image.jpg';
        var mailcomposer = Meteor.npmRequire("mailcomposer");
        var mailOptions = {
            rejectUnhauthorized : false,
            from: "xxx@gmail.com",
            to: email,
            subject: "Report",
            html: html,
            attachments: [
              {
                  filename: "report.xlsx",
                  content: file,
                  encoding: 'binary',
                  contentType: 'application/octet-stream',
                  contentTransferEncoding: 'base64'
              }
            ]
          }
          
 var mail = mailcomposer(mailOptions);
        var stream = mail.createReadStream();
        stream.pipe(process.stdout); 
        mail.build(function(err, message){
            process.stdout.write(message);
        });
        
        transporter.sendMail(mailOptions, function(error, info){
            if(error){
                return console.log(error);
            }
            console.log('Mail sent: ', info);
        });
      }

How to send it correctly


#2

Meteor’s Email package uses mailComposer 0.1.15, which does not seem to support all the options you have used. Perhaps try removing the encoding and contentTransferEncoding options?


#3

I have already tried removing encoding and contentTransferEncoding but that doesn’t work, output is same.