GmailThread

A thread in a user's Gmail account.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#addLabel(GmailLabel)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Adds this label to the thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of the last message in this thread using the reply-to address. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of the last message in this thread using the reply-to address, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of the last message in this thread, using the reply-to address and all recipients of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of the last message in this thread, using the reply-to address and all recipients, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getFirstMessageSubject()` | `String` | Gets the subject of the first message in the thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getId()` | `String` | Gets the ID of this thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getLabels()` | `https://developers.google.com/apps-script/reference/gmail/gmail-label` | Returns the user-created labels on this thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getLastMessageDate()` | `Date` | Gets the date of this thread's most recent message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getMessageCount()` | `Integer` | Returns the number of messages in the thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getMessages()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message` | Gets the messages in this thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getPermalink()` | `String` | Gets a permalink for this thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#hasStarredMessages()` | `Boolean` | Returns whether the thread has any starred messages. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isImportant()` | `Boolean` | Returns whether the thread is marked as important. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isInChats()` | `Boolean` | Returns whether the thread is labeled a chat. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isInInbox()` | `Boolean` | Returns whether the thread is in the inbox. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isInPriorityInbox()` | `Boolean` | Returns true if this thread is in the priority inbox; returns false otherwise. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isInSpam()` | `Boolean` | Returns whether the thread is marked as spam. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isInTrash()` | `Boolean` | Returns whether the thread is in the trash. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#isUnread()` | `Boolean` | Returns whether the thread has any unread messages. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markImportant()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Marks this thread as important. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markRead()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Marks this thread as read. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markUnimportant()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Marks this thread as unimportant. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markUnread()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Marks this thread as unread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#moveToArchive()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Moves this thread to the archive. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#moveToInbox()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Moves this thread to the inbox. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#moveToSpam()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Moves this thread to spam. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#moveToTrash()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Moves this thread to the trash. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#refresh()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Reloads this thread, and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#removeLabel(GmailLabel)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Removes this label from the thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Reply to the sender of the last message on this thread using the replyTo address. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Reply to the sender of the last message on this thread using the replyTo address, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Reply to the sender (using the replyTo address), and all recipients of the last message on this thread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread#` | Reply to the sender (using the `replyTo` address), and all recipients of the last message on this thread, with optional arguments. |

## Detailed documentation

### `addLabel(label)`

Adds this label to the thread.

```javascript
// Add label MyLabel to the first thread in the inbox
const label = GmailApp.getUserLabelByName('MyLabel');
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.addLabel(label);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `label` | `https://developers.google.com/apps-script/reference/gmail/gmail-label` | the label to apply to this thread |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#removeLabel(GmailLabel)`

*** ** * ** ***

### `createDraftReply(body)`

Creates a draft message replying to the sender of the last message in this thread using the
reply-to address. The size of the email (including headers) is [quota limited](https://developers.google.com/apps-script/guides/services/quotas#current_limitations).

```javascript
// Create a draft reply to the message author with an acknowledgement.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.createDraftReply('Got your message');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-draft` --- the newly created draft message

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReply(body, options)`

Creates a draft message replying to the sender of the last message in this thread using the
reply-to address, with optional arguments.

The email can contain both plain text and an HTML body. The size of the email (including
headers) is [quota
limited](https://developers.google.com/apps-script/guides/services/quotas#current_limitations).

```javascript
// Create a draft response with an HTML text body.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.createDraftReply('incapable of HTML', {
  htmlBody: '<b>some HTML body text</b>',
  cc: 'another@example.com',
});
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |
| `options` | `Object` | a JavaScript object that specifies advanced parameters, as listed below |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `attachments` | `https://developers.google.com/apps-script/reference/base/blob-source.html` | an array of files to send with the email |
| `bcc` | `String` | a comma-separated list of email addresses to BCC |
| `cc` | `String` | a comma-separated list of email addresses to CC |
| `from` | `String` | the address that the email should be sent from, which must be one of the values returned by `https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()` |
| `htmlBody` | `String` | if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional `inlineImages` field in HTML body if you have inlined images for your email |
| `inlineImages` | `Object` | a JavaScript object containing a mapping from image key (`String`) to image data (`https://developers.google.com/apps-script/reference/base/blob-source.html`); this assumes that the `htmlBody` parameter is used and contains references to these images in the format `<img src="cid:imageKey" />` |
| `name` | `String` | the name of the sender of the email (default: the user's name) |
| `replyTo` | `String` | an email address to use as the default reply-to address (default: the user's email address) |
| `subject` | `String` | a new subject line for the email (250 characters maximum) |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-draft` --- the newly created draft message

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReplyAll(body)`

Creates a draft message replying to the sender of the last message in this thread, using the
reply-to address and all recipients of this message. The size of the email (including headers)
is [quota limited](https://developers.google.com/apps-script/guides/services/quotas#current_limitations).

```javascript
// Create a draft reply to all recipients (except those bcc'd) of the last email
// in this thread.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.createDraftReplyAll('Got your message');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-draft` --- the newly created draft message

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReplyAll(body, options)`

Creates a draft message replying to the sender of the last message in this thread, using the
reply-to address and all recipients, with optional arguments.

The email can contain both plain text and an HTML body. The size of the email (including
headers) is [quota
limited](https://developers.google.com/apps-script/guides/services/quotas#current_limitations).

```javascript
// Create a draft reply, using an HTML text body, to all recipients (except
// those bcc'd) of the last email of in this thread.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.createDraftReplyAll('incapable of HTML', {
  htmlBody: '<b>some HTML body text</b>',
  cc: 'another@example.com',
});
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |
| `options` | `Object` | a JavaScript object that specifies advanced parameters, as listed below |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `attachments` | `https://developers.google.com/apps-script/reference/base/blob-source.html` | an array of files to send with the email |
| `bcc` | `String` | a comma-separated list of email addresses to BCC |
| `cc` | `String` | a comma-separated list of email addresses to CC |
| `from` | `String` | the address that the email should be sent from, which must be one of the values returned by `https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()` |
| `htmlBody` | `String` | if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional `inlineImages` field in HTML body if you have inlined images for your email |
| `inlineImages` | `Object` | a JavaScript object containing a mapping from image key (`String`) to image data (`https://developers.google.com/apps-script/reference/base/blob-source.html`); this assumes that the `htmlBody` parameter is used and contains references to these images in the format `<img src="cid:imageKey" />` |
| `name` | `String` | the name of the sender of the email (default: the user's name) |
| `replyTo` | `String` | an email address to use as the default reply-to address (default: the user's email address) |
| `subject` | `String` | a new subject line for the email. Max size is 250 chars. |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-draft` --- the newly created draft message

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#createDraftReplyAll(String)`

*** ** * ** ***

### `getFirstMessageSubject()`

Gets the subject of the first message in the thread.

```javascript
// Log the subject of the first message in the first thread in the inbox
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(firstThread.getFirstMessageSubject());
```

#### Return


`String` --- the subject of the first message in the thread

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getLastMessageDate()`

*** ** * ** ***

### `getId()`

Gets the ID of this thread. The ID of a thread varies based on the messages it contains; for a
consistent ID for a particular message in the thread, call `getMessages()[0].getId()`
instead.

```javascript
// Log the subject of the first message in the first thread in the inbox.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const id = firstThread.getId();
// Get same thread by its ID.
const thread = GmailApp.getThreadById(id);
Logger.log(
    thread.getFirstMessageSubject() === firstThread.getFirstMessageSubject(),
);  // True
```

#### Return


`String` --- the ID of this thread

*** ** * ** ***

### `getLabels()`

Returns the user-created labels on this thread.

```javascript
// Log the names of the labels attached to the first thread in the inbox
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const labels = firstThread.getLabels();
for (let i = 0; i < labels.length; i++) {
  Logger.log(labels[i].getName());
}
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-label` --- an array of labels for this thread

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `getLastMessageDate()`

Gets the date of this thread's most recent message.

```javascript
// Log the date of the most recent message on the first thread in the inbox
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(firstThread.getLastMessageDate());
```

#### Return


`Date` --- the date of the most recent message in the thread

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getFirstMessageSubject()`

*** ** * ** ***

### `getMessageCount()`

Returns the number of messages in the thread.

```javascript
// Log the number of messages in the thread
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(firstThread.getMessageCount());
```

#### Return


`Integer` --- the number of messages in the thread

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getMessages()`

*** ** * ** ***

### `getMessages()`

Gets the messages in this thread.

```javascript
// Log the subjects of the messages in the thread
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const messages = firstThread.getMessages();
for (let i = 0; i < messages.length; i++) {
  Logger.log(messages[i].getSubject());
}
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message` --- an array of Gmail messages in this thread

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#getMessageCount()`

*** ** * ** ***

### `getPermalink()`

Gets a permalink for this thread.

Note that this only works with the classic Gmail interface, not Inbox.

```javascript
// Logs the permalink for the first thread in the inbox
const thread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(thread.getPermalink());
```

#### Return


`String` --- the permalink for this thread

*** ** * ** ***

### `hasStarredMessages()`

Returns whether the thread has any starred messages.

```javascript
// Log if this thread has starred messages
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`has starred : ${firstThread.hasStarredMessages()}`);
```

#### Return


`Boolean` --- true if the thread has any starred messages

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isImportant()`

Returns whether the thread is marked as important.

```javascript
// Log if this thread is marked as important
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`Important? : ${firstThread.isImportant()}`);
```

#### Return


`Boolean` --- Whether the thread is marked as important.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isInChats()`

Returns whether the thread is labeled a chat.

```javascript
// Log if this thread is a chat
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`is in chats? : ${firstThread.isInChats()}`);
```

#### Return


`Boolean` --- true if the thread is labeled a chat

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isInInbox()`

Returns whether the thread is in the inbox.

```javascript
// Log if this thread is in the inbox
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`is in the inbox? : ${firstThread.isInInbox()}`);
```

#### Return


`Boolean` --- true if the thread is in the inbox

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isInPriorityInbox()`

Returns true if this thread is in the priority inbox; returns false otherwise.

```javascript
// Log if this thread is in the priority inbox
const firstThread = GmailApp.getPriorityInboxThreads(0, 1)[0];
Logger.log(`is in priority inbox? ${firstThread.isInPriorityInbox()}`);
```

#### Return


`Boolean` --- true if the thread is in the priority inbox

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isInSpam()`

Returns whether the thread is marked as spam.

```javascript
// Log if this thread is in the spam folder
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`Spam? ${firstThread.isInSpam()}`);
```

#### Return


`Boolean` --- Whether this thread is marked as spam.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isInTrash()`

Returns whether the thread is in the trash.

```javascript
// Log if this thread is in the trash
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`Trashed? ${firstThread.isInTrash()}`);
```

#### Return


`Boolean` --- true if the thread is in the trash

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `isUnread()`

Returns whether the thread has any unread messages.

```javascript
// Log if this thread is unread
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
Logger.log(`Unread? ${firstThread.isUnread()}`);
```

#### Return


`Boolean` --- true if there are unread messages

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `markImportant()`

Marks this thread as important.

```javascript
// Mark first inbox thread as important
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.markImportant();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markUnimportant()`

*** ** * ** ***

### `markRead()`

Marks this thread as read.

```javascript
// Mark first inbox thread as read
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.markRead();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markUnread()`

*** ** * ** ***

### `markUnimportant()`

Marks this thread as unimportant.

```javascript
// Mark first inbox thread as unimportant
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.markUnimportant();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markImportant()`

*** ** * ** ***

### `markUnread()`

Marks this thread as unread.

```javascript
// Mark first inbox thread as unread
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.markUnread();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#markRead()`

*** ** * ** ***

### `moveToArchive()`

Moves this thread to the archive.

```javascript
// Archive first inbox thread
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.moveToArchive();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `moveToInbox()`

Moves this thread to the inbox.

```javascript
// Move first non-inbox thread to inbox
const firstThread = GmailApp.search('-in:inbox')[0];
firstThread.moveToInbox();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `moveToSpam()`

Moves this thread to spam.

```javascript
// Move first inbox thread to spam
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.moveToSpam();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `moveToTrash()`

Moves this thread to the trash.

```javascript
// Move first inbox thread to trash
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.moveToTrash();
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `refresh()`

Reloads this thread, and associated state from Gmail (useful in case the labels, read state,
etc., have changed).

```javascript
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
// ...Do something that may take a while here....
firstThread.refresh();  // Make sure it's up-to-date
// ...Do more stuff with firstThread ...
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

*** ** * ** ***

### `removeLabel(label)`

Removes this label from the thread.

```javascript
const myLabel = GmailApp.getUserLabelByName('<your label>');
const threads = myLabel.getThreads();
for (const thread of threads) {
  thread.removeLabel(myLabel);
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `label` | `https://developers.google.com/apps-script/reference/gmail/gmail-label` | the label to remove from this thread |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#addLabel(GmailLabel)`

*** ** * ** ***

### `reply(body)`

Reply to the sender of the last message on this thread using the replyTo address.

Note that the total size of the email (including all headers) may not exceed 20KB.

```javascript
// Respond to author of last email in thread with acknowledgment
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.reply('Got your message');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)`

*** ** * ** ***

### `reply(body, options)`

Reply to the sender of the last message on this thread using the replyTo address, with optional
arguments. The email can contain both plain text, and also an HTML body. Note that the total
size of the email (including all headers, but excluding attachments) may not exceed 20KB.

```javascript
// Respond with HTML body text.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.reply('incapable of HTML', {
  htmlBody: 'some HTML body text',
  noReply: true,
});
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |
| `options` | `Object` | a JavaScript object that specifies advanced parameters, as listed below |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `cc` | `String` | a comma separated list of email addresses to CC |
| `bcc` | `String` | a comma separated list of email addresses to BCC |
| `htmlBody` | `String` | if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional `inlineImages` field in HTML body if you have inlined images for your email |
| `name` | `String` | the name of the sender of the email (default: the user's name) |
| `from` | `String` | the address that the email should be sent from, which must be one of the values returned by `https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()` |
| `replyTo` | `String` | an email address to use as the default reply-to address (default: the user's email address) |
| `noReply` | `Boolean` | `true` if the email should be sent from a generic no-reply email address to discourage recipients from responding to emails; this option is only possible for Google Workspace accounts, not Gmail users |
| `attachments` | `https://developers.google.com/apps-script/reference/base/blob-source.html` | an array of files to send with the email |
| `inlineImages` | `Object` | a JavaScript object containing a mapping from image key (`String`) to image data (`https://developers.google.com/apps-script/reference/base/blob-source.html`); this assumes that the `htmlBody` parameter is used and contains references to these images in the format `<img src="cid:imageKey" />` |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)`

*** ** * ** ***

### `replyAll(body)`

Reply to the sender (using the replyTo address), and all recipients of the last message on this
thread.

Note that the total size of the email (including all headers) may not exceed 20KB.

```javascript
// Respond to all with acknowledgment to the first thread in the inbox
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.replyAll('Got your message');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)`

*** ** * ** ***

### `replyAll(body, options)`

Reply to the sender (using the `replyTo` address), and all recipients of the last message
on this thread, with optional arguments. The email can contain both plain text, and also an
HTML body. Note that the total size of the email (including all headers, but excluding
attachments) may not exceed 20KB.

```javascript
// Respond with HTML body text.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
firstThread.replyAll('incapable of HTML', {
  htmlBody: 'some HTML body text',
  noReply: true,
});
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `body` | `String` | the body of the email |
| `options` | `Object` | a JavaScript object that specifies advanced parameters, as listed below |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `cc` | `String` | a comma separated list of email addresses to CC |
| `bcc` | `String` | a comma separated list of email addresses to BCC |
| `htmlBody` | `String` | if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional `inlineImages` field in HTML body if you have inlined images for your email |
| `name` | `String` | the name of the sender of the email (default: the user's name) |
| `from` | `String` | the address that the email should be sent from, which must be one of the values returned by `https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()` |
| `replyTo` | `String` | an email address to use as the default reply-to address (default: the user's email address) |
| `noReply` | `Boolean` | `true` if the email should be sent from a generic no-reply email address to discourage recipients from responding to emails; this option is only possible for G Suite accounts, not Gmail users |
| `attachments` | `https://developers.google.com/apps-script/reference/base/blob-source.html` | an array of files to send with the email |
| `inlineImages` | `Object` | a JavaScript object containing a mapping from image key (`String`) to image data (`https://developers.google.com/apps-script/reference/base/blob-source.html`); this assumes that the `htmlBody` parameter is used and contains references to these images in the format `<img src="cid:imageKey" />` |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread#` --- this thread, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes#gmailv1):

- `https://mail.google.com/`

#### See also

- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-thread#replyAll(String,Object)`