Generating a CSV file and sending it through email on button press

Hi everyone,

I’m a beginner with Retool and not an advanced developer (at all!). I've been facing a wall for a couple hours now. I’m working on building an interface for a client that allows them to view and edit values in a database. The process is straightforward: they can modify data in a table and click a button to update the database.

As part of this functionality, I’m trying to set up an automated email that sends me a CSV file containing the updated data every time the button is pressed.

So far, I’ve managed to configure the email to send with a file attached. However, the attached CSV file seems to be corrupted or poorly encoded—I can’t open it properly or make sense of its content.

Here’s what I’ve done so far:

Generating the CSV:

Linkin it in the email query:

The file I'm receiving looks like this:

I’ve been troubleshooting this for hours and combing through forums but haven’t found a solution. Could someone point me in the right direction? Is there an issue with how I’m generating or attaching the CSV?

Thanks a million!

Hi @Nisshin,

Welcome to Retool! :slight_smile:

Try editing line 7 in your code snippet to:

const csvContent = btoa(Papa.unparse(filteredData)); //

Just confirmed on my side that should work! :white_check_mark:

It worked perfectly, thanks a million for your help, Tess!