简体   繁体   中英

How to send excel (.xlsx) file with nodemailer?

I've tried numerous ways to do it using the github README.md guide, but every time I receive an email, it contains 0 bytes. What am I doing wrong?

Basic setup:

const smtpTransport = mailer.createTransport({
    service: "Gmail",
    auth: {
        user: gmailEmail,
        pass: gmailPass
    }
});
let wef = fs.readFileSync("./" + fileName);
let mailOptions = {
    to: ['myemail@gmail.com'],
    subject: 'Subject line'
    attachments: [{
        contents: new Buffer(wef)
    }]
};
smtpTransport.sendMail(mailOptions, function(error, response) {
    smtpTransport.close();
    cb(error || null);
});

I've tried tons of combinations with changing the mailOptions by adding different attachment types, different contents, different contentTypes, and no matter what I do, I always get a file with 0 bytes. Not sure why.

Update: Nodemailer is crap, don't use it. Ended up using 'gmail-send', works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM