【问题标题】:Send html text as attachment to sendgrid将 html 文本作为附件发送到 sendgrid
【发布时间】:2020-07-31 17:14:26
【问题描述】:

我将文本作为 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)

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

【问题讨论】:

    标签: javascript node.js sendgrid sendgrid-api-v3


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

    请参阅此link 以获取 MIME 映射的文件扩展名。

    【讨论】:

    • data_base64 应该是什么?谢谢:)
    • 使用 data_base64 = window.btoa(htmlcontent) ,其中 htmlcontent 将是您的 html 文本
    • 是nodejs。我无权访问窗口。我该怎么办?
    • nvm 有一个 npm 代码。 npmjs.com/package/btoa
    • 我试过文件名:book.id + ".html",内容:btoa(book.body),类型:'text/html',处置:'附件'
    猜你喜欢
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    • 2020-06-27
    • 2013-01-03
    相关资源
    最近更新 更多