使用PDFkit通过Nodemailer发送base64编码的PDF

问题描述 投票:0回答:1

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

关于nodemailer文档,我发现了这个例子:

const mailOptions = {
    from: '[email protected]', // sender address
    to: '[email protected]', // 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: '[email protected]' // should be as unique as possible
        },

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

node.js pdf attachment nodemailer pdfkit
1个回答
0
投票

好的,这都是格式化问题。

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

  const mailOptions = {
    from: '[email protected]', // sender address
    to: '[email protected]', // list of receivers
    subject: "Hey this is a subject example", //subject
    attachments: [
      {
        filename: `myfile.pdf`,
        content: 'THISISAB64STRING',
        encoding: 'base64',
      },
    ],
  };

然后以经典的方式发送它。

© www.soinside.com 2019 - 2024. All rights reserved.