我正在使用 Sendgrid 使用 Nodejs 通过 Firebase Cloud Functions 发送交易电子邮件。
const attachment = file.createReadStream();
const msg = {
to: email,
from: "test@test.com",
subject: "print order",
templateId: "templateid",
dynamic_template_data: {
dashboardurl: `/order#${orderId}`,
downloadurl: orderData.downloadurl
},
attachments: [{
content: attachment,
filename: "order.pdf",
type: "application/pdf",
disposition: "attachment"
}]
};
await sgMail.send(msg);
由于以下错误,电子邮件不会发送:
TypeError: Converting circular structure to JSON
Firebase 存储解决方案
const tempFilePath = path.join(os.tmpdir(), "tmp.pdf");
await file.download({ destination: tempFilePath });
const attachment = fs.readFileSync(tempFilePath, { encoding: "base64" });