0

I've tried all the stack codes I've found here:

            filename: 'my-file.pdf',
            content:  Buffer('base64code', 'base64'),

            contentType: 'application/pdf'

filename: 'your.pdf',
content: 'encodedpdfstring', //EncodedString
encoding: 'base64'

Etc, but nothing works.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Ethan Apr 19 '22 at 20:15

1 Answers1

0

I don't know whether it will work for you or not, I was using SendGrid. And this is how I did. I first utilize the html-pdf-node npm package to generate pdfBuffer out of HTML code.

let file = { content: emailTemplate };
let options = { format: "A4" };
const pdfBuffer = await html_to_pdf.generatePdf(file, options);

And then, SENDGRID.send method to basically send an email, with body content and pdf as an attachment

await SENDGRID.send({
      from,
      to,
      html,
      subject,
      attachments: [
        {
          content: pdfBuffer.toString("base64"),
          filename: filename,
          type: "application/pdf",
          disposition: "attachment",
        },
      ],
    });

Properties I passed above are:

From(email) - from whom
to(email) - to whom
html - the body content as an HTML code
subject - email subject
filename - filename of the attachment e.g. my_file.pdf

I hope it will help :)

Mohsin
  • 97
  • 10
  • thanks for your answer, I ended up sending the pdfBytes, coz nodemailder accepts it. I didn't use sendgrid coz I cant create an account! – Balahaus Bengala Apr 27 '22 at 02:54