gpt4 book ai didi

node.js - 使用 PDFkit 通过 Nodemailer 发送 base64 编码的 PDF

转载 作者:行者123 更新时间:2023-12-02 03:29:58 27 4
gpt4 key购买 nike

我有一个函数可以返回一个base64编码的PDF,我想使用nodemailer将其作为附件PDF文件发送。

关于nodemailer文档,我找到了这个例子:

const mailOptions = {
from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcb9b1bdb5b0ed9cbbb1bdb5b0f2bfb3b1" rel="noreferrer noopener nofollow">[email protected]</a>', // sender address
to: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adc8c0ccc4c19fedcac0ccc4c183cec2c0" rel="noreferrer noopener nofollow">[email protected]</a>', // list of receivers
subject: 'Simulation', // Subject line
html: '<p>SALUT</p>', // plain text body
filename: 'file.pdf',
attachments: [
content: Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
'base64'
),

cid: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="452b2a312005203d24283529206b262a28" rel="noreferrer noopener nofollow">[email protected]</a>' // should be as unique as possible
},

但是,这对我不起作用。我错过了什么吗?

最佳答案

好吧,这都是格式问题。

以下是如何在 Nodemailer 上使用 B64:

  const mailOptions = {
from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62070f030b0e5322050f030b0e4c010d0f" rel="noreferrer noopener nofollow">[email protected]</a>', // sender address
to: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03666e626a6f3143646e626a6f2d606c6e" rel="noreferrer noopener nofollow">[email protected]</a>', // list of receivers
subject: "Hey this is a subject example", //subject
attachments: [
{
filename: `myfile.pdf`,
content: 'THISISAB64STRING',
encoding: 'base64',
},
],
};

然后以经典方式发送即可。

关于node.js - 使用 PDFkit 通过 Nodemailer 发送 base64 编码的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52129886/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com