Sending an attachment using the Postal API

Hi there!

For the last few days, I’ve been hard at work on getting my installation up and running and letting it do a lot of the things I have been doing manually.

One of those things is setting up a system to pick up any invoice I create and send it over to my accountant. Until now, I did that manually. But starting now, it’ll simply mail a copy of an invoice the second it is created.

In order to do that, I’d need to use the Postal API, since I use Postal for all of my automated mail traffic. However, I don’t like using the SMTP option (it just is more bother than it solves for me in Postal, to be honest), so I wanted this to work with N8N and Postal.

The big issue is: there is no integration for N8N and Postal, so I had to figure it out on my own. That wasn’t too hard, however, sending an attachment drove me crazy. In the end, this is how I did it in N8N:

{{[{"name": $data.fileName, "content_type": $data.fileType, "data": $data.attachment}]}}

To explain this a bit further: in order to send an attachment through the Postal API, you need to pass through an associative array with the keys: “name”, “content_type” and the base64 encoded version of your attachment. You can pass through multiple arrays to send multiple attachments.

So, this is what your JSON array should look like:

"attachments" : [
    "name": "attachmentname.pdf",
    "content_type": "application/pdf", 
    "data": "some_base64_encoded string"

If you pass that through, you should be able to send your mail, with an attachment, through Postal v2.

Do you have any further questions, or can’t get it to work? Feel free to poke me.

  • Kevin

Posted on Friday, 8 July 2022