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

Hello all,

As a followup, if you're interested in sending attachments with the Gmail API you'll need to use a different endpoint and slightly different formatting.

Google docs: 上传附件  |  Gmail  |  Google for Developers

Transformer:

Query:

EDIT:
Copyable transformer code:

const to = {{to.value}}
const from = {{from.value}}
const subject = {{subject.value}}
const body = {{body.value}}

const fileType = {{filepicker1.file.contentType}}
const fileData = {{filepicker1.file.data}}
const fileName = {{filepicker1.file.name}}
  

const messageParts = [
  'Content-Type: multipart/mixed; boundary="message_section"',
  'MIME-Version: 1.0',
  `From: ${from}`,
  `To: ${to}`,
  `Subject: ${subject}`,
  
  '--message_section',
  'Content-Type: text/plain; charset="UTF-8"',
  'MIME-Version: 1.0',
  'Content-Transfer-Encoding: 7bit',
  '',
  body,
  '',

  '--message_section',
  `Content-Type: ${fileType}`,
  'MIME-Version: 1.0',
  'Content-Transfer-Encoding: base64',
  `Content-Disposition: attachment; filename=${fileName}`,
  '',
  fileData,
  '',
  '--message_section--'
];

return messageParts.join('\r\n');
4 Likes