我有一个函数可以返回base64编码的PDF,我想使用nodemailer将其作为附件PDF文件发送。
关于nodemailer文档,我找到了以下示例:
const mailOptions = {
from: 'email1@gmail.com', // sender address
to: 'email2@gmail.com', // 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: 'note@example.com' // should be as unique as possible
},
但是,这对我不起作用。我想念什么吗?
答案 0 :(得分:0)
好吧,这都是格式化问题。
以下是如何在Nodemailer上使用B64:
const mailOptions = {
from: 'email1@gmail.com', // sender address
to: 'email2@gmail.com', // list of receivers
subject: "Hey this is a subject example", //subject
attachments: [
{
filename: `myfile.pdf`,
content: 'THISISAB64STRING',
encoding: 'base64',
},
],
};
然后以经典方式发送。