CSV文件,因为附件在发送电子邮件时失败

时间:2018-07-17 12:19:17

标签: node.js sendgrid

我正在使用sendgrid发送电子邮件,而我正在做的是,我正在发送csv文件作为附件。但是以某种方式给了我错误。我的代码如下所示:

fs.readFile('file.csv', (err, data) => {
                    if (err) {
                        console.log('oops something went wrong');
                    }
                    else {


                        console.log('data is ' +data);


                        const msg = {
                            to: "email@email.com",
                            from: process.env.EMAIL_ID,
                            subject: 'test',
                            attachments: [{
                                filename: 'file.csv',
                                content: new Buffer(data).toString("base64"),
                                type: 'text/plain',
                                disposition: 'attachment',
                                contentId: 'file.csv'
                            }]
                        }

                        sgMail.send(msg, (err, info) => {
                            if (err) {
                                console.log('error is ' + err);
                            }
                        });
                    }
                })

对于此代码,它给我错误,如下所示:

error is Bad Request (400)
  Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block. We typically suggest both text/plain and text/html blocks are included, but only one block is required.
    content
    http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content

0 个答案:

没有答案