# Gmail

> Send, read, and manage email from your Gmail account.

App · Email · 14 actions · 1 trigger. Web page: https://docs.lodol.com/docs/integrations/gmail

## Triggers

Start a workflow when something happens in Gmail. See [how triggers work](https://docs.lodol.com/docs/concepts/triggers.md).

### Gmail New Email

Triggers when a new email arrives in your Gmail inbox

**Filters**: Narrow which events start a run.

- `sender`

**Event fields**: What a run starts with. Later steps read each field with an @ reference.

- `email_id` (text)
- `thread_id` (text)
- `from` (text)
- `to` (text)
- `subject` (text)
- `date` (text)
- `body` (text)

## Actions

### Add label to message

Add a label to a Gmail message.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID
- Label name (`label_name`, text, required): Name of the label to add
- Create if missing (`create_if_missing`, true/false): Create the label if it does not exist. Default: `true`.

**Outputs**

- `label_id` (text): Label ID
- `message_id` (text): Message ID
- `thread_id` (text): Thread ID

**Example output**

```json
{
  "label_id": "Label_123",
  "message_id": "18abc123def456",
  "thread_id": "18abc123def456"
}
```

### Archive email

Archive a Gmail message so it no longer appears in the inbox.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID

**Outputs**: No return value

**Example output**

```json
{}
```

### Create draft

Create an email draft in Gmail. Set 'Reply to message' to draft a reply inside that email's conversation; nothing is sent.

**Inputs**

- To (`to`, text): Recipient email address(es). Separate multiple recipients (including variables) with commas. Required unless 'Reply to message' is set, when leaving it blank addresses the draft to that email's sender.
- Subject (`subject`, text): Email subject line. Required unless 'Reply to message' is set, when leaving it blank reuses that email's subject with a 'Re:' prefix.
- Body (`body`, text, required): Plain text body of the email
- CC (`cc`, text): Optional Cc recipients. Separate multiple addresses (including variables) with commas.
- BCC (`bcc`, text): Optional Bcc recipients. Separate multiple addresses (including variables) with commas.
- Reply to message (`reply_to_message_id`, text): The ID of an email to draft a reply to. The draft is saved in that email's conversation and threads with it when sent. Leave blank for a new email.

**Outputs**

- `id` (text): Draft ID
- `message_id` (text): Message ID

**Example output**

```json
{
  "id": "r123456789",
  "message_id": "18abc123def456"
}
```

### Create label

Create a new Gmail label.

**Inputs**

- Label (`label`, text, required): Name of the label to create
- Label list visibility (`label_list_visibility`, text): Whether the label appears in Gmail's label list
- Message list visibility (`message_list_visibility`, text): Whether the label appears in Gmail's message list

**Outputs**

- `label` (text): Label name
- `label_id` (text): Label ID
- `label_list_visibility` (text): Label list visibility
- `message_list_visibility` (text): Message list visibility

**Example output**

```json
{
  "label": "My Label",
  "label_id": "Label_123",
  "label_list_visibility": "labelShow",
  "message_list_visibility": "show"
}
```

### Create reply message

Create a reply message in a thread.

**Inputs**

- Message to reply to (`message_id`, text, required): The ID of the email to reply to
- Subject (`subject`, text): Email subject line. Leave blank to reuse the original email's subject with a 'Re:' prefix.
- Body (`body`, text, required): Plain text body of the reply
- Attachments (`attachments`, list): Files to attach to the reply. Upload a file or reference a document (or list of documents) from an earlier step.
- CC (`cc`, text): Optional Cc recipients. Separate multiple addresses (including variables) with commas.
- BCC (`bcc`, text): Optional Bcc recipients. Separate multiple addresses (including variables) with commas.

**Outputs**: No return value

**Example output**

```json
{}
```

### Delete email

Move a Gmail message to the trash.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID

**Outputs**: No return value

### Download attachments

Download all attachments from a Gmail message.

**Inputs**

- Sender (`sender`, text, required): Only download attachments from emails sent by this address

**Outputs**

- `document_refs` (list): References to the downloaded attachments, usable as file inputs in later steps (e.g. an email's attachments field).
- `documents` (list): Downloaded attachment metadata.

**Example output**

```json
{
  "document_refs": [
    "doc_0123456789abcdef0123456789abcdea",
    "doc_0123456789abcdef0123456789abcdeb"
  ],
  "documents": [
    {
      "content_type": "application/pdf",
      "document_ref": "doc_0123456789abcdef0123456789abcdea",
      "filename": "attachment1.pdf",
      "size_bytes": 2048
    },
    {
      "content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
      "document_ref": "doc_0123456789abcdef0123456789abcdeb",
      "filename": "attachment2.docx",
      "size_bytes": 4096
    }
  ]
}
```

### Find email

Find the first Gmail email that matches your search.

**Inputs**

- Search query (`query`, text, required): What to search for, using Gmail's search format
- Unread only (`unread_only`, true/false): If true, only search unread emails. Default: `false`.
- In inbox (`in_inbox`, true/false): If true, only search in inbox. Default: `false`.

**Outputs**: Object containing the found email, or email: null if not found

- `email` (object): Found email or null if not found

**Example output**

```json
{
  "email": {
    "body": "Hey, just wanted to follow up on our conversation from last week. Let me know if you have any questions.",
    "from": "sender@example.com",
    "id": "18abc123def456",
    "reply_body": "Hey, just wanted to follow up on our conversation from last week. Let me know if you have any questions.",
    "sender": "sender@example.com",
    "snippet": "Hey, just wanted to follow up on...",
    "subject": "Hello",
    "thread_id": "18abc123def456"
  }
}
```

### Get message headers

Get the header details of a Gmail message, such as From, To, Subject, and Date.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID

**Outputs**: Dictionary of email headers

**Example output**

```json
{
  "Date": "Mon, 1 Jan 2024 12:00:00 +0000",
  "From": "sender@example.com",
  "Subject": "Hello World",
  "To": "recipient@example.com",
  "threadId": "18abc123def456"
}
```

### Get most recent email

Get the most recently received email from your Gmail inbox.

**Inputs**: None.

**Outputs**: Most recent email details

- `date` (text): Email date
- `from_` (text): Sender email address
- `id` (text): Gmail message ID
- `snippet` (text): Email snippet preview
- `subject` (text): Email subject
- `thread_id` (text): Thread ID

**Example output**

```json
{
  "date": "Mon, 1 Jan 2024 12:00:00 +0000",
  "from_": "sender@example.com",
  "id": "18abc123def456",
  "snippet": "This is a preview of the email content...",
  "subject": "Hello World",
  "thread_id": "18abc123def456"
}
```

### List emails

List emails matching filters and return message details.

**Inputs**

- Limit (`limit`, number): Maximum number of emails to return
- Search query (`q`, text): What to search for, using Gmail's search format (for example, from:foo@example.com)
- Unread only (`unread_only`, true/false): If true, only return unread emails. Default: `false`.
- In inbox (`in_inbox`, true/false): If true, only return emails in the inbox. Default: `true`.

**Outputs**: List of Gmail emails under `emails`

- `emails` (list)

**Example output**

```json
{
  "emails": [
    {
      "body": "Hello there, this is the full email body content.",
      "from": "sender@example.com",
      "id": "18abc123def456",
      "reply_body": "Hello there, this is the full email body content.",
      "sender": "sender@example.com",
      "snippet": "Hello there",
      "subject": "Hello",
      "thread_id": "18abc123def456"
    }
  ]
}
```

### Mark as read

Mark a Gmail message as read.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID

**Outputs**: No return value

### Remove label from message

Remove a label from a Gmail message.

**Inputs**

- Message ID (`message_id`, text, required): Gmail message ID
- Label name (`label_name`, text, required): Name of the label to remove

**Outputs**

- `label_id` (text): Label ID
- `message_id` (text): Message ID
- `thread_id` (text): Thread ID

**Example output**

```json
{
  "label_id": "Label_123",
  "message_id": "18abc123def456",
  "thread_id": "18abc123def456"
}
```

### Send message

Send an email message or reply to a thread.

**Inputs**

- To (`to`, text, required): Recipient email address(es). Separate multiple recipients (including variables) with commas.
- Subject (`subject`, text, required): Email subject line
- Body (`body`, text, required): Plain text body of the email
- Attachments (`attachments`, list): Files to attach to the email. Upload a file or reference a document (or list of documents) from an earlier step.
- CC (`cc`, text): Optional Cc recipients. Separate multiple addresses (including variables) with commas.
- BCC (`bcc`, text): Optional Bcc recipients. Separate multiple addresses (including variables) with commas.

**Outputs**: No return value

**Example output**

```json
{}
```
