ActiveCampaign/postmark.js

PDF email attachments not sending?

Closed this issue · 2 comments

I am trying to send pdf attachments in a templated email, but they are not sending. I am trying to convert to base64 as per the docs, but still, nothing works. The email sends just fine, it is only missing the attachments. The path for the attachment is completely correct.

Code sample:

pmark.sendEmailWithTemplate({
  "From": "tickets@sample.com",
  "To": "don@sample.com",
  "TemplateID": 28419047,
  "TemplateModel": {
    event_name: "Test Event",
    Attachments: [
      {
        "Name": "thing.pdf",
        "Content": fs.readFileSync('./temp/thing.pdf').toString("base64"),
        "ContentType": "application/pdf"
      }
    ]
  }
})

If I console.log(fs.readFileSync('./temp/thing.pdf').toString("base64")) then I get a giant string.

Any help?

I got it to work by using the method in the doc:

let message = new postmark.Models.Message("sample@sample", "Test subject", "Html body", "Text body","don@sample.com");
      const attachment1 = new postmark.Models.Attachment("report.txt", Buffer.from("test").toString("base64"), "text");
      const attachment2 = new postmark.Models.Attachment("book.pdf", fs.readFileSync('./temp/thing.pdf').toString("base64"), "application/pdf");
      message.Attachments = [attachment1, attachment2]
      message.TemplateID = 28419047
      delete message.HtmlBody
      delete message.TextBody
      delete message.Subject
      message.TemplateModel = {
        attendee_name: `John Doe`,
     }
        pmark.sendEmailWithTemplate(message)

But it seems unoptimal, I can't find any documentation on how the new postmark.Models.Message function really works but it seems it was designed for a regular message, not a templated one. Therefore I have to pass dummy subject, htmlbody, textbody in, then delete them afterward since those fields do not apply to a templated send.

Hi There @Donny-H

could you share more details what do you mean by postmark.Models.Message being used for templates? TemplatedMessage is used for sending with templates which doesn't request any dummy parameters - https://github.com/ActiveCampaign/postmark.js/blob/main/src/client/models/templates/Template.ts

These can be all checked for client documentation .

The library is based on our Postmark Developer API , feel free to check it out here.

In case you need to load faster/easier attachments, it should be straightforward to add wrappers that would set the parameters that Postmark API requires.