javascript - 将 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 来做到这一点。我更新了上面的代码。
解决方案
- 为提供的文件名添加合适的扩展名(例如booksummary.html)
- 将类型值替换为正确的 MIME 类型 ( text/html )
有关 MIME 映射的文件扩展名,请参阅此链接。
推荐阅读
- vue.js - Nuxt fetchUser Auth 功能不是反应性的,需要硬刷新
- mysql - 如何将 SQL 表中的所有值转换为具有多列的单行
- linq - 如何将 FirstOrDefaultAsync EF Linq 返回到实体列表查询
- apache-kafka - kstream-ktable join实现后如何处理Apache kafka中丢失的数据
- asp.net - web.config 在 IIS 10 上正常工作并在 IIS 8.5 上返回 403 错误
- java - 依赖管理中的冗余
- sql - 我如何使用 Microsoft SQL MANAGER 上的 SQL 过滤这个新的 IIF 列的位置
- grid - 顺风网格部分的自动高度
- javascript - 插入jquery javascript后选择元素
- jboss - 迁移到 JBOSS 7.4 和 Java11 后未正确注入 EJB 无状态 bean