我想将 PDF 添加到我使用 Courier 发送的电子邮件中。我已将我的账户设置为使用 Amazon SES 作为我的电子邮件提供商。我正在使用 Courier Node.js SDK 发送消息:
const courier = CourierClient();
const { messageId } = await courier.send({
eventId: "MONTHLY_BILLING",
recipientId: "81462728-70d2-4d71-ab44-9d627913f1dd",
data: {
"tennant_id": "W5793",
"tennant_name": "Oscorp, Inc.",
"billing_date": {
"month": "November",
"year": "2020"
},
"amount": 99.0
}
});
我如何才能将发票包含为 PDF 格式?
您可以使用提供商覆盖来包含附件。每个提供商的覆盖都不同,但您可以在 Courier 文档中了解有关 AWS SES 覆盖 的更多信息。
您需要获取要附加为 Base64 编码字符串的文件。这将根据您的文件所在位置而有所不同。要从文件系统检索文件,您可以执行以下操作:
const fs = require('fs');
const file = fs.readFileSync("/path/to/file");
const strFile = new Buffer(file).toString("base64");
现在您可以更新您的快递发送方法以包含覆盖:
const courier = CourierClient();
const { messageId } = await courier.send({
eventId: "MONTHLY_BILLING",
recipientId: "81462728-70d2-4d71-ab44-9d627913f1dd",
data: {
"tennant_id": "W5793",
"tennant_name": "Oscorp, Inc.",
"billing_date": {
"month": "November",
"year": "2020"
},
"amount": 99.0
},
override: {
"aws-ses": {
attachments: [
{
fileName: "FileName.pdf",
contentType: "application/pdf",
data: strFile
}
]
}
}
});