# Gmail (/integrations/gmail)

Use [Gmail](https://mail.google.com/) to send or draft messages, read and search mail, and manage labels and read status. Gmail triggers can start a workflow when new mail arrives.

## OAuth scopes \[#oauth-scopes]

Sim requests these scopes when someone connects a Gmail account. For a self-hosted deployment, register your own app with the provider using the settings below. See [Integrations and OAuth](/platform/self-hosting/integrations-oauth) for setup.

| Setting | Value |
| - | - |
| Redirect URI | `<NEXT_PUBLIC_APP_URL>/api/auth/oauth2/callback/google-email` |
| Environment variables | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` |

| Scope | Description |
| - | - |
| `https://www.googleapis.com/auth/userinfo.email` | View email address |
| `https://www.googleapis.com/auth/userinfo.profile` | View basic profile info |
| `https://www.googleapis.com/auth/gmail.send` | Send emails |
| `https://www.googleapis.com/auth/gmail.modify` | Read, compose, send, and modify email messages |
| `https://www.googleapis.com/auth/gmail.labels` | View and manage email labels |

## Use the block \[#usage-instructions]

Send or draft messages, read and search mail, and manage labels and read status. New-mail triggers can start workflows.

## Actions \[#actions]

### Gmail Send \[#gmail-send]

Send emails using Gmail.

#### Input \[#input]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `to` | string | Yes | Recipient email address |
| `subject` | string | No | Email subject |
| `body` | string | Yes | Email body content |
| `contentType` | string | No | Content type for the email body (text or html) |
| `threadId` | string | No | Thread ID to reply to (for threading) |
| `replyToMessageId` | string | No | Gmail message ID to reply to - use the "id" field from Gmail Read results (not "rfcMessageId") |
| `cc` | string | No | CC recipients (comma-separated) |
| `bcc` | string | No | BCC recipients (comma-separated) |
| `replyTo` | string | No | Reply-To address that replies should go to (e.g., <support@example.com>) |
| `attachments` | file\[] | No | Files to attach to the email |

#### Output \[#output]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Email labels |

### Gmail Draft \[#gmail-draft]

Draft emails using Gmail.

#### Input \[#input-1]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `to` | string | Yes | Recipient email address |
| `subject` | string | No | Email subject |
| `body` | string | Yes | Email body content |
| `contentType` | string | No | Content type for the email body (text or html) |
| `threadId` | string | No | Thread ID to reply to (for threading) |
| `replyToMessageId` | string | No | Gmail message ID to reply to - use the "id" field from Gmail Read results (not "rfcMessageId") |
| `cc` | string | No | CC recipients (comma-separated) |
| `bcc` | string | No | BCC recipients (comma-separated) |
| `replyTo` | string | No | Reply-To address that replies should go to (e.g., <support@example.com>) |
| `attachments` | file\[] | No | Files to attach to the email draft |

#### Output \[#output-1]

| Parameter | Type | Description |
| - | - | - |
| `draftId` | string | Draft ID |
| `messageId` | string | Gmail message ID for the draft |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Email labels |

### Gmail Edit Draft \[#gmail-edit-draft]

Update an existing Gmail draft in place without deleting and recreating it.

#### Input \[#input-2]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `draftId` | string | Yes | ID of the draft to update (from Gmail List Drafts or Gmail Get Draft) |
| `to` | string | Yes | Recipient email address |
| `subject` | string | No | Email subject |
| `body` | string | Yes | Email body content |
| `contentType` | string | No | Content type for the email body (text or html) |
| `threadId` | string | No | Thread ID to associate the draft with (for threading) |
| `replyToMessageId` | string | No | Gmail message ID to reply to - use the "id" field from Gmail Read results (not "rfcMessageId") |
| `cc` | string | No | CC recipients (comma-separated) |
| `bcc` | string | No | BCC recipients (comma-separated) |
| `replyTo` | string | No | Reply-To address that replies should go to (e.g., <support@example.com>) |
| `attachments` | file\[] | No | Files to attach to the email draft |

#### Output \[#output-2]

| Parameter | Type | Description |
| - | - | - |
| `draftId` | string | Draft ID |
| `messageId` | string | Gmail message ID for the draft |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Email labels |

### Gmail Read \[#gmail-read]

Read emails from Gmail.

#### Input \[#input-3]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | No | Gmail message ID to read (e.g., 18f1a2b3c4d5e6f7) |
| `folder` | string | No | Folder/label to read emails from (e.g., INBOX, SENT, DRAFT, TRASH, SPAM, or custom label name) |
| `unreadOnly` | boolean | No | Set to true to only retrieve unread messages |
| `maxResults` | number | No | Maximum number of messages to retrieve (default: 1, max: 10) |
| `includeAttachments` | boolean | No | Set to true to download and include email attachments |

#### Output \[#output-3]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Email labels |
| `from` | string | Sender email address |
| `to` | string | Recipient email address |
| `cc` | string | Cc recipients (raw Cc header) |
| `bcc` | string | Bcc recipients (only present on messages you sent or drafted) |
| `replyTo` | string | Reply-To header |
| `subject` | string | Email subject |
| `date` | string | Email date |
| `rfcMessageId` | string | RFC Message-ID header (not the Gmail message id) |
| `inReplyTo` | string | In-Reply-To header |
| `references` | string | References header |
| `snippet` | string | Short excerpt of the message text |
| `internalDate` | string | Gmail internal creation timestamp in epoch milliseconds |
| `body` | string | Email body text (best-effort plain text) |
| `hasAttachments` | boolean | Whether the email has attachments |
| `attachmentCount` | number | Number of attachments |
| `attachments` | file\[] | Downloaded attachments (if enabled) |
| `results` | json | Summary results when reading multiple messages (id, threadId, subject, from, to, cc, bcc, replyTo, date, rfcMessageId, inReplyTo, references, snippet, internalDate) |

### Gmail Search \[#gmail-search]

Search emails in Gmail.

#### Input \[#input-4]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `query` | string | Yes | Search query for emails |
| `maxResults` | number | No | Maximum number of results to return (e.g., 10, 25, 50; Gmail default: 100, max: 500) |
| `pageToken` | string | No | Page token from a previous search (nextPageToken) to fetch the next page |

#### Output \[#output-4]

| Parameter | Type | Description |
| - | - | - |
| `results` | json | Array of search results (id, threadId, subject, from, to, cc, bcc, replyTo, date, snippet, rfcMessageId, inReplyTo, references, internalDate) |
| `nextPageToken` | string | Token for fetching the next page of results |
| `resultSizeEstimate` | number | Estimated total number of results |

### Gmail Move \[#gmail-move]

Move emails between labels/folders in Gmail.

#### Input \[#input-5]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to move |
| `addLabelIds` | string | Yes | Comma-separated label IDs to add (e.g., INBOX, Label_123) |
| `removeLabelIds` | string | No | Comma-separated label IDs to remove (e.g., INBOX, SPAM) |

#### Output \[#output-5]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Email labels |

### Gmail Mark as Read \[#gmail-mark-as-read]

Mark a Gmail message as read.

#### Input \[#input-6]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to mark as read |

#### Output \[#output-6]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Mark as Unread \[#gmail-mark-as-unread]

Mark a Gmail message as unread.

#### Input \[#input-7]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to mark as unread |

#### Output \[#output-7]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Archive \[#gmail-archive]

Archive a Gmail message (remove from inbox).

#### Input \[#input-8]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to archive |

#### Output \[#output-8]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Unarchive \[#gmail-unarchive]

Unarchive a Gmail message (move back to inbox).

#### Input \[#input-9]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to unarchive |

#### Output \[#output-9]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Delete \[#gmail-delete]

Delete a Gmail message (move to trash).

#### Input \[#input-10]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to delete |

#### Output \[#output-10]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Add Label \[#gmail-add-label]

Add label(s) to a Gmail message.

#### Input \[#input-11]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to add labels to |
| `labelIds` | string | Yes | Comma-separated label IDs to add (e.g., INBOX, Label_123) |

#### Output \[#output-11]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail Remove Label \[#gmail-remove-label]

Remove label(s) from a Gmail message.

#### Input \[#input-12]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `messageId` | string | Yes | ID of the message to remove labels from |
| `labelIds` | string | Yes | Comma-separated label IDs to remove (e.g., INBOX, Label_123) |

#### Output \[#output-12]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `labelIds` | array | Updated email labels |

### Gmail List Labels \[#gmail-list-labels]

List all labels in a Gmail account

#### Input \[#input-13]

| Parameter | Type | Required | Description |
| - | - | - | - |

#### Output \[#output-13]

| Parameter | Type | Description |
| - | - | - |
| `labels` | json | Array of label objects with id, name, type, and visibility settings |

### Gmail Create Label \[#gmail-create-label]

Create a new label in Gmail

#### Input \[#input-14]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `name` | string | Yes | Display name for the new label |
| `messageListVisibility` | string | No | Visibility of messages with this label in the message list (show or hide) |
| `labelListVisibility` | string | No | Visibility of the label in the label list (labelShow, labelShowIfUnread, or labelHide) |

#### Output \[#output-14]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Label ID |
| `name` | string | Label display name |
| `messageListVisibility` | string | Visibility of messages with this label |
| `labelListVisibility` | string | Visibility of the label in the label list |
| `type` | string | Label type (system or user) |

### Gmail Update Label \[#gmail-update-label]

Update a Gmail label in place (rename or change visibility) without recreating it

#### Input \[#input-15]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `labelId` | string | Yes | ID of the label to update (from Gmail List Labels) |
| `name` | string | No | New display name for the label |
| `messageListVisibility` | string | No | Visibility of messages with this label in the message list (show or hide) |
| `labelListVisibility` | string | No | Visibility of the label in the label list (labelShow, labelShowIfUnread, or labelHide) |

#### Output \[#output-15]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Label ID |
| `name` | string | Label display name |
| `messageListVisibility` | string | Visibility of messages with this label |
| `labelListVisibility` | string | Visibility of the label in the label list |
| `type` | string | Label type (system or user) |

### Gmail Delete Label \[#gmail-delete-label]

Delete a label from Gmail

#### Input \[#input-16]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `labelId` | string | Yes | ID of the label to delete |

#### Output \[#output-16]

| Parameter | Type | Description |
| - | - | - |
| `deleted` | boolean | Whether the label was successfully deleted |
| `labelId` | string | ID of the deleted label |

### Gmail List Drafts \[#gmail-list-drafts]

List all drafts in a Gmail account

#### Input \[#input-17]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `maxResults` | number | No | Maximum number of drafts to return (default: 100, max: 500) |
| `pageToken` | string | No | Page token for paginated results |
| `query` | string | No | Search query to filter drafts (same syntax as Gmail search) |

#### Output \[#output-17]

| Parameter | Type | Description |
| - | - | - |
| `drafts` | json | Array of draft objects with id, messageId, and threadId |
| `resultSizeEstimate` | number | Estimated total number of drafts |
| `nextPageToken` | string | Token for fetching the next page of results |

### Gmail Get Draft \[#gmail-get-draft]

Get a specific draft from Gmail by its ID

#### Input \[#input-18]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `draftId` | string | Yes | ID of the draft to retrieve |

#### Output \[#output-18]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Draft ID |
| `messageId` | string | Gmail message ID |
| `threadId` | string | Gmail thread ID |
| `to` | string | Recipient email address |
| `from` | string | Sender email address |
| `cc` | string | Cc recipients |
| `bcc` | string | Bcc recipients |
| `replyTo` | string | Reply-To header |
| `subject` | string | Draft subject |
| `date` | string | Date header |
| `rfcMessageId` | string | RFC Message-ID header (not the Gmail message id) |
| `inReplyTo` | string | In-Reply-To header |
| `references` | string | References header |
| `snippet` | string | Short excerpt of the draft text |
| `body` | string | Draft body text |
| `labelIds` | array | Draft labels |

### Gmail Delete Draft \[#gmail-delete-draft]

Delete a specific draft from Gmail

#### Input \[#input-19]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `draftId` | string | Yes | ID of the draft to delete |

#### Output \[#output-19]

| Parameter | Type | Description |
| - | - | - |
| `deleted` | boolean | Whether the draft was successfully deleted |
| `draftId` | string | ID of the deleted draft |

### Gmail List Threads \[#gmail-list-threads]

List email threads in a Gmail account

#### Input \[#input-20]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `maxResults` | number | No | Maximum number of threads to return (default: 100, max: 500) |
| `pageToken` | string | No | Page token for paginated results |
| `query` | string | No | Search query to filter threads (same syntax as Gmail search) |
| `labelIds` | string | No | Comma-separated label IDs to filter threads by |

#### Output \[#output-20]

| Parameter | Type | Description |
| - | - | - |
| `threads` | json | Array of thread objects with id, snippet, and historyId |
| `resultSizeEstimate` | number | Estimated total number of threads |
| `nextPageToken` | string | Token for fetching the next page of results |

### Gmail Get Thread \[#gmail-get-thread]

Get a specific email thread from Gmail, including all messages in the thread

#### Input \[#input-21]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `threadId` | string | Yes | ID of the thread to retrieve |
| `format` | string | No | Format to return the messages in (full, metadata, or minimal). Defaults to full. |

#### Output \[#output-21]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Thread ID |
| `historyId` | string | History ID |
| `snippet` | string | Short excerpt of the thread |
| `messages` | json | Array of messages in the thread with id, threadId, labelIds, snippet, from, to, cc, bcc, replyTo, subject, date, rfcMessageId, inReplyTo, references, internalDate, and body |

### Gmail Trash Thread \[#gmail-trash-thread]

Move an email thread to trash in Gmail

#### Input \[#input-22]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `threadId` | string | Yes | ID of the thread to trash |

#### Output \[#output-22]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Thread ID |
| `trashed` | boolean | Whether the thread was successfully trashed |

### Gmail Untrash Thread \[#gmail-untrash-thread]

Remove an email thread from trash in Gmail

#### Input \[#input-23]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `threadId` | string | Yes | ID of the thread to untrash |

#### Output \[#output-23]

| Parameter | Type | Description |
| - | - | - |
| `id` | string | Thread ID |
| `untrashed` | boolean | Whether the thread was successfully removed from trash |

## Triggers \[#triggers]

A trigger starts a workflow when a supported event occurs in this service.

These triggers poll for new data on a schedule.

### Gmail Email Trigger \[#gmail-email-trigger]

Triggers when new emails are received in Gmail (requires Gmail credentials)

Configuration and outputs

#### Configuration \[#configuration]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `triggerCredentials` | string | Yes | This trigger requires google email credentials to access your account. |
| `labelIds` | string | No | Choose which Gmail labels to monitor. Leave empty to monitor all emails. |
| `labelFilterBehavior` | string | Yes | Include only emails with selected labels, or exclude emails with selected labels |
| `searchQuery` | string | No | Optional Gmail search query to filter emails. Use the same format as Gmail search box (e.g., "subject:invoice", "from:<boss@company.com>", "has:attachment"). Leave empty to search all emails. |
| `markAsRead` | boolean | No | Automatically mark emails as read after processing |
| `includeAttachments` | boolean | No | Download and include email attachments in the trigger payload |

#### Output \[#output-24]

| Parameter | Type | Description |
| - | - | - |
| `email` | object | |
| ↳ `id` | string | Gmail message ID |
| ↳ `threadId` | string | Gmail thread ID |
| ↳ `subject` | string | Email subject line |
| ↳ `from` | string | Sender email address |
| ↳ `to` | string | Recipient email address |
| ↳ `cc` | string | CC recipients |
| ↳ `bcc` | string | BCC recipients (only present on messages you sent) |
| ↳ `replyTo` | string | Reply-To header |
| ↳ `rfcMessageId` | string | RFC Message-ID header (not the Gmail message ID) |
| ↳ `inReplyTo` | string | In-Reply-To header (RFC Message-ID of the parent message) |
| ↳ `references` | string | References header (RFC Message-IDs in the thread) |
| ↳ `snippet` | string | Short excerpt of the message text |
| ↳ `date` | string | Email date in ISO format |
| ↳ `bodyText` | string | Plain text email body |
| ↳ `bodyHtml` | string | HTML email body |
| ↳ `labels` | array | Email labels array |
| ↳ `hasAttachments` | boolean | Whether email has attachments |
| ↳ `attachments` | file\[] | Array of email attachments as files (if includeAttachments is enabled) |
| `timestamp` | string | Event timestamp |
