How do I Send Email From Retool Table w/ GMail API

Hey @hadenp92, I was building out an internal Retool application that used the Gmail API and ran into the same issue. I solved it by adapting Google's send.js example code.

First, you'll want to create a Transformer to encode your inputs into a base64-encoded message. Using the inputs your provided in the screenshot, it should look something like this:

const to = {{table1.selectedRow.data.Email}}
const subject = 'Your subject'
const body = 'Message body'
const from = 'from-address@example.com'

const utf8Subject = `=?utf-8?B?${btoa(subject)}?=`;
const messageParts = [
  `From: ${from}`,
  `To: ${to}`,
  'Content-Type: text/html; charset=utf-8',
  'MIME-Version: 1.0',
  `Subject: ${utf8Subject}`,
  '',
  body,
];
const message = messageParts.join('\n');

// The body needs to be base64url encoded.
const encodedMessage =  btoa(message)
  .replace(/\+/g, '-')
  .replace(/\//g, '_')
  .replace(/=+$/, '');

return encodedMessage

You'll then want to update your query. The Body section should have a single raw parameter set to the value of your transformer. I'm assuming that the transformer is named transformer1.

Using this setup, I was able to successfully send an email. I could not figure out how to support the snippet parameter. I also didn't see the contact_name parameter documented for send

2 Likes