Save/Email PDF files

Hi All,

We currently have a form (new employee) which when submitted; saves to the database and also generates a PDF. What I would like to happen is for an email to be sent to HR with this new PDF attached, every time the form is submitted.

The only way (we think) would be manually; save the PDF to storage - create file attach button - attach the saved PDF. Then create a email query which sends the results of this attach input to whomever we need to.

Any suggestions on how we could automate this process or make it easier would be appreciated.
Thanks

Hello!

How/Where is the PDF saved after the form submission? If the base64 data can be obtained you should be able to attach the PDF to your outgoing e-mail without needing someone to grab the file from storage.

I think this post pretty much covers it but please let us know if there is any additional follow-up help you require.

Hi,
Thank you for getting in touch again @pyrrho ! Is there a step-by-step guide on how we could do that? As there is some confusion (on our side) from that post. On each submit, it would be a different PDF each time - so how could we get around that in terms of using the correct URL etc.

Thanks

Hello again!

Can you post some screenshots from your app that show the submission query creating the PDF? Once you have the PDF content generated, how is is "saved"?

I'm not sure exactly what is going on behind the scenes, but the idea would be to find the generated data's base64 content and then use that as the e-mail attachment.



Hi,
The PDF is saved in local storage, like other regular browser downloads. As for attaching the content, would that be done manually each time?

(images uploaded)
Thanks, again

Oh, excellent! So, by default, the generatePDF query will still download this through the browser but after it is done the output data will be available for you to use in a follow up event/query.

Here is the example PDF Exporter content after running the default query:

The e-mail you are sending needs this file.data output to use as the attachment using the following format (from the previously linked post):

[{
  "name": generatePDF.data.file.name, 
  "type": "application/pdf", 
  "sizeBytes": atob(generatePDF.data.file.data).length,
  "base64Data": generatePDF.data.file.data
}]

For whatever reason, the in-line Attachments area of the E-mail query doesn't like this format, but I ran it through a JS Query to return the data for me and that worked:

image

Using this output in the query:

ETA: final delivered e-mail:

Thank you for your reply @pyrrho,
I have followed the steps you mention but get the following error;



I have a separate button which runs the generate query and another button for the email query.

Apologies for the amateur developing skills :sob:

Hrm, that's strange. The only weird thing I see is an empty subject line.

I wonder if you have a file upload component currently linked to this query. Can you bring up the state of the query and look at the bottom to see if there is a file drop component linked as dependency?

image

This is for the sendEmail query;
image

I just got the same error trying to run without first processing my JavaScript query. Are you still running in the query window or are you trying to run the full process from your button click?

I'm trying to run the full process from button click...

That works for me too - attaching the JS query to a submit button (which also generates the PDF) - then a 'email' button which runs the sendEmail query. I need to continue testing by generating new PDF files but looks good for now.

Thanks again!

1 Like

I wanted to add multiple uploaded images using the file upload component as multiple attachments to an email. But I am using gmail api to send it and didn’t have time to figure out how to do this with gmail. So I just add the public retool storage links in the email body. For me that works for now.

This might be a less difficult solution for some on this forum so I wanted to mention it.

I will bookmark this post for when I want to attach images to the email and use it as a tutorial. Thank you for sharing! :ok_hand:

3 Likes