【问题标题】:parse data to CSV send email use nodeMailer Node.JS将数据解析为 CSV 发送电子邮件使用 nodeMailer Node.JS
【发布时间】:2020-06-03 17:50:13
【问题描述】:

我一直在查看有关附件的 nodeMailer 文档,我遇到的问题需要发送如下所示的数据字符串,我需要将它们转换为 CSV,然后通过 nodeMailer 发送。

看到另一个数组到 CSV 的帖子,提到我需要在发送之前解析,所以我尝试使用 papaparse 数据并传入他们的自定义附件,但我会收到错误。

在节点中设置

const attachment = 
    ""test1,","test2,","test3,","test4,"" 
const parseInfo = papaparse.parse(attachment, {delimiter: ",", newline: ""})

const options = {
  to: toAddress,
  from: fromAddress,
  subject: subject,
  text: text,
  html: html,
  attachments:{ // define custom content type for the attachment
    filename: 'sample.csv',
    content: parseData,
    contentType: 'text/csv'
  },
};

错误信息

An error occured while sending the email ---:TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object

我错过了什么吗?感谢您的帮助!

【问题讨论】:

标签: javascript export-to-csv nodemailer papaparse


【解决方案1】:

我的数据已经是一个字符串,所以我不需要解析日期,我直接作为内容传入,然后就可以了。必须确保文件名带有 .csv 和 contentType: 'text/csv'。 希望对遇到和我一样问题的人有所帮助。

const attachment = 
    `"test1,","test2,","test3,","test4"`
const options = {
  to: toAddress,
  from: fromAddress,
  subject: subject,
  text: text,
  html: html,
  attachments:{ // define custom content type for the attachment
    filename: 'sample.csv',
    content: parseData,
    contentType: 'text/csv'
  },
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 2021-08-23
    • 2020-11-17
    • 2015-05-19
    相关资源
    最近更新 更多