简体   繁体   中英

Send email with attachments after a file is generated

I'm running an approval flow that generates an index.html table file with all items requested.

There is a button to approve all requests and a button to generate a.csv file.

I need to send an email to whoever approves the request (after clicking the “approve all” button) with the.csv file as an attachment. Is there any way I can do this?

Thanks in advance.

Nodemailer supports different ways of setting attachments .

var nodemailer = require('nodemailer');
        

 var transporter = nodemailer.createTransport({
      host: 'host.com',
      port: 465,
      secure: true,
      service: 'gmail',
      auth: {
           user: 'user@gmail.com',
           pass: 'gmailpassword'
      }
});
    
var mailOptions = {
     from: 'sender@gmail.com',
     to: 'receiver@gmail.com',
     subject: 'CSV File',
     text: 'Hello world',
     html: '<b>Hello world</b>',
     attachments: [{
         filename: 'csv-file.csv', // file name
         path: '/path/to/csv-file.csv' // file path
     }]
 };

// send mail
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        console.log(error);
    }
    console.log(info.response);
});

you can use convert data into CSV before sending it. Use module like papaparse .
NodeMailer -> Nodemailer Repository GitHub

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