首页 > 解决方案 > 将 html 文本作为附件发送到 sendgrid

问题描述

我在数据库中将文本存储为 html。我想将该文本转换为可以使用 sendgrid 作为附件发送的文件。有谁知道怎么做?这是我到目前为止所拥有的

         var body = {
        subject: book.title + " test Original",
        personalizations:
            [{
                to: [{email: to,}]
            }],
        content: [{type: "text/plain", value: book.title + " book summary"}],
        from: {email: 'info@test.com', name: 'test Team'},
        attachments: [
            {
                filename: book.id + ".html",
                content: btoa(book.body),
                type: 'text/html',
                disposition: 'attachment'
            }
        ]
    };
    this.sendMail(body)

我想使用节点和 javascript 来做到这一点。我更新了上面的代码。

标签: javascriptnode.jssendgridsendgrid-api-v3

解决方案


  • 为提供的文件名添加合适的扩展名(例如booksummary.html
  • 将类型值替换为正确的 MIME 类型 ( text/html )

有关 MIME 映射的文件扩展名,请参阅此链接


推荐阅读