Packs, Codas word for integrations with other services, allow Coda to truly become the all-in-one doc. Bringing your teams work from all over the internet into one unified space.
The Gmail pack for Coda, one of the most popular packs, is lacking one major feature though
The Gmail pack for Coda cannot send email messages containing attachments
While the Gmail pack may not be able to send emails with attachments, that does not mean that Coda cannot do it.
The guide below will demonstrate how to use Apps Script, a Google providing coding environment, to easily send emails with attachments using a button in Coda. Apps Script does require the use of a little bit of code, but I promise you can do it.
Yes you - Although you have never written a line of code before, you can do this.
Step 1: Create an Apps Script project
The first step is setting up a new Apps-Script. You can do this by:
Once you have navigated to Google Apps-Script you are going need to start a new project (hint: if you typed script.new into your browser, you automatically created a new project already! No need to start a new one)
You will be greeted by a screen like this - even if it looks intimidating stick with me! It looks far more intimidating than it actually is.
Step 2: Set up your Apps Script
Alright! Now its time to actually get our code in our project, and set it up so its ready to connect to your Coda doc.
Copy/Paste Code
Now that you have your new Apps Script project up and running we need to insert the code snippet. You can do that by copying the code snippet below and pasting it into your apps-script project
function replaceSpace(name){
return name.replace(/ /g, '_')
}
function sendPdfEmail(url,to,subject,body,pdfName){
let response = UrlFetchApp.fetch(url) //The Coda hosted URL of your PDF file
let pdfBlob = response.getBlob();
let newPdfName = replaceSpace(pdfName) // Replacing the space in the Coda provided name
pdfBlob.setName(newPdfName);
MailApp.sendEmail(to,subject,body,{
attachments: [pdfBlob]
})
}
function doPost(e){
let info = JSON.parse(e.postData.contents);
let to = info.to;
let subject = info.subject;
let url = info.url;
let body = info.body;
let pdfName = info.pdfName;
sendPdfEmail(url,to,subject,body,pdfName);
}
Get ready to connect to Coda
Alright - now that you’ve got your code in the project its time to set up your project and ensure it is able to connect to Coda. You will have to do three quick things:
- Save the project
- Run the project to authorize it
- Deploy the project as an application
First lets save your project using the save button
Next, you will need to RUN the project in order to authorize it. Authorizing it is similar to inputting a username and password - you are telling the Apps Script that it is ok to send emails on your behalf.
To run the script you need to choose a function to run. Make sure you are running the replaceSpace function then hit the run button
Once you press Run you will be walked through the normal flow of signing in/logging in with your gmail account.
Now that you’ve done that theres only one more step to go - its time to deploy your script as a web app.
In order to to that, follow these steps:
- Press the big blue DEPLOY button in the top right corner of your screen
- Choose “New Deployment”
- Select the “Web App” deployment type using the small cog wheel in the top left of the pop-up window
- Change the “Who has access” to be “Anyone”
- Press Deploy!
- Once deployed, it will give you both a deployment ID and a URL. You want to copy the URL specifically and save it for the next step
Step 3: Set up Coda to send emails!
You did it! You now have a script running that will accept inputs from a Coda doc and send Gmail messages with attachments. Now we just have to connect our Coda doc to your apps script and set up the actual button that will do all the magic.
You’ve only got a couple steps left and then you are done:
- Install the Apps Script pack into the Coda doc you want to send messages from
- Configure the button to send messages
- Send your first email!
Install the Apps Script Pack
There is a free pack in the Coda gallery called “Apps Script” - and you can install it in any Coda doc by doing the following:
Inside a Coda doc:
- Insert > Packs > Search “Apps Script” > Add to doc for free
The Apps Script pack is going to have a button that allows us to trigger or send information from a Coda doc directly to your apps-script project you created in the previous step.
Configure a button to send your email
Sending emails from a button is best done from a table. If you need to learn more about sending emails from Coda in general, here’s a resource that runs you through best practices.
Likely, if you have a table to send emails it will look like the following with common column types of name, email, subject, attachment, name of attachment, etc. But honestly, you can set up the table however your workflow demands
Once you have your table, create a new button column, and choose a pack action, and choose the Apps Script pack and then choose the “Trigger web app” action
Once you have your button in your table its time to configure, or set it up. You will need to input the following things into your button
- The Web App URL you copied from Step 2 of this guide
- Method: Type the word “POST” into this box
- Body: This is going to be a formula input - use the JsonBody() formula from the Apps Script pack.
For the Body part of the button, this is where you will define what information from your Coda doc gets sent out to the apps-script, and then eventually in the email. It should look exactly like the image below
The parts that need to be exact are the words
And then the value or the argument directly after the “url” portion needs to be the Attachment.First()._merge().ParseJSON(”publicUrl”) formula. All the other green chips will be unique to your document or table
A fully configured button will look like this:
And thats it! Now you can start sending emails with attachments from any Coda doc.
A little more about this workflow
This workflow is just one way that Coda docs can be extended using Apps Script. SimplaDocs has built dozens of Apps scripts for clients that connect to their Coda docs in a myriad of ways automating all sorts of business processes
While apps script can be used for any sort of automations, it is especially helpful for automations or integrations with Google based services.
Don’t hesitate to contact us if you need any help!
Enjoyed learning more about Coda with this post and want to learn more? From Coda lover to Coda lover, we've selected some other interesting and useful resources we think you'll love. Check them below👇