Setu Recipes: reusable workflows across every app.Browse templates

Integrations / Gmail

Gmail

Read, search and draft email in a connected Gmail account.

6 actions OAuth 2 3 read2 write1 destructive Calls gmail.googleapis.com

Connect

TypeScript
const conn = await setu.connections.initiate({ userId: "user_1", toolkit: "gmail" });
console.log(conn.connectUrl); // show this to your user
await conn.waitUntilActive();

Permissions requested

ScopeWhy it is requested
https://www.googleapis.com/auth/userinfo.emailSee which Google account you connected
https://www.googleapis.com/auth/gmail.readonlyRead your email messages and settings
https://www.googleapis.com/auth/gmail.composeCreate drafts and send email for you

Actions

Create draftwritegmail.create_draftSave an email as a draft in Gmail without sending it. Safe way to let an AI prepare a reply.

Needs scope: https://www.googleapis.com/auth/gmail.compose

InputTypeDescription
tostringRequiredRecipient address, or several separated by commas
ccstringOptionalOptional cc address
subjectstringRequiredSubject line
textstringRequiredPlain text body
thread_idstringOptionalOptional thread ID to reply into
TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.create_draft",
  input: {
    "to": "<to>",
    "subject": "<subject>",
    "text": "<text>"
  },
});
Delete draftdestructivegmail.delete_draftDelete a draft from Gmail.

Needs scope: https://www.googleapis.com/auth/gmail.compose

InputTypeDescription
draft_idstringRequiredDraft ID
TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.delete_draft",
  input: {
    "draft_id": "<draft_id>"
  },
  confirm: true,
});
Get messagereadgmail.get_messageRead one message: its headers, a short snippet and the encoded body.

Needs scope: https://www.googleapis.com/auth/gmail.readonly

InputTypeDescription
message_idstringRequiredMessage ID from list_messages
formatstringOptionalmetadata is smallest, full includes the body
TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.get_message",
  input: {
    "message_id": "<message_id>"
  },
});
List labelsreadgmail.list_labelsList the labels in the mailbox, such as Inbox, Sent and custom labels.

Needs scope: https://www.googleapis.com/auth/gmail.readonly

No input.

TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.list_labels",
  input: {},
});
List messagesreadgmail.list_messagesSearch or list recent messages. Use Gmail search syntax in q, for example from:alice newer_than:7d.

Needs scope: https://www.googleapis.com/auth/gmail.readonly

InputTypeDescription
qstringOptionalGmail search query
max_resultsintegerOptionalUp to 100
page_tokenstringOptionalFrom a previous call
TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.list_messages",
  input: {},
});
Send emailwritegmail.send_emailSend an email from the connected Gmail account. This cannot be unsent, so it should be approved first.

Needs scope: https://www.googleapis.com/auth/gmail.compose

InputTypeDescription
tostringRequiredRecipient address, or several separated by commas
ccstringOptionalOptional cc address
subjectstringRequiredSubject line
textstringRequiredPlain text body
thread_idstringOptionalOptional thread ID to reply into
TypeScript
await setu.execute({
  userId: "user_1",
  action: "gmail.send_email",
  input: {
    "to": "<to>",
    "subject": "<subject>",
    "text": "<text>"
  },
});