Solving SendGrid PDF Email Attachment Issue on Make.com

Have you ever tried to send a PDF file as an email attachment using the SendGrid module and ended up with a corrupted file or a .txt file full of random characters? If so, you're not alone. This is a common problem faced by many Make.com users. But don't worry, we have a solution for you.

Problem

When you get a .pdf file in a base64 string from a web hook and try to send it as an email attachment using the SendGrid module, you might end up with a corrupted .pdf file or a .txt file full of random characters.

Solution

The problem occurs because the binary data you get contains the encoding parameter as well. You need to remove the 'data:application/pdf;base64,' part so it only leaves you with the actual binary data. You can use the replace() function to do this.

If the encoding is dynamic and changes depending on the file type, you can use RegEx to say "remove everything to the left of the first ‘comma’". Here's how you can do it:

{{replace("data:application/pdf;base64,s87shdfui32nuiwehf8ef"; "/.+base64\,/"; emptystring)}}

Replace the static base64 text with the variable you have.

Troubleshooting Tips

If you still get a .txt file with the entire binary in it, try adding a ‘.pdf’ at the end of the file name. This should solve the problem.

Summary

In this article, we discussed a common problem faced by Make.com users when trying to send a PDF file as an email attachment using the SendGrid module. We provided a step-by-step solution to the problem and also shared some troubleshooting tips. We hope this article helps you if you ever face a similar challenge.

You do have further questions?

Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.