GmailMessage

A message in a user's Gmail account.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of this message using the reply-to address. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of this message using the reply-to address, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender using the reply-to address and all recipients of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-draft` | Creates a draft message replying to the sender of this message using the reply-to address and all recipients, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#forward(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Forwards this message to new recipients. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#forward(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Forwards this message to new recipients, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getAttachments()` | `https://developers.google.com/apps-script/reference/gmail/gmail-attachment` | Gets all the attachments for this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getAttachments(Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-attachment` | Gets all the attachments for this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getBcc()` | `String` | Gets the comma-separated recipients bcc'd on this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getBody()` | `String` | Gets the HTML content of the body of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getCc()` | `String` | Gets the comma-separated recipients cc'd on this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getDate()` | `Date` | Gets the date and time of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getFrom()` | `String` | Gets the sender of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getHeader(String)` | `String` | Gets the value of an RFC 2822 header given the header name. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getId()` | `String` | Gets the ID of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getPlainBody()` | `String` | Gets the content of the body of this message without HTML formatting. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getRawContent()` | `String` | Gets the raw content of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getReplyTo()` | `String` | Gets the reply-to address of this message (usually the sender). |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getSubject()` | `String` | Gets the subject of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getThread()` | `https://developers.google.com/apps-script/reference/gmail/gmail-thread` | Gets the thread that contains this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#getTo()` | `String` | Gets the comma-separated recipients of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isDraft()` | `Boolean` | Gets whether this message is a draft. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isInChats()` | `Boolean` | Gets whether this message is a chat. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isInInbox()` | `Boolean` | Gets whether this message is in the inbox. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isInPriorityInbox()` | `Boolean` | Returns `true` if this message is in the priority inbox; returns `false` otherwise. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isInTrash()` | `Boolean` | Gets whether this message is in the trash. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isStarred()` | `Boolean` | Gets whether this message is starred. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#isUnread()` | `Boolean` | Gets whether this message is unread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#markRead()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Marks the message as read. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#markUnread()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Marks the message as unread. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#moveToTrash()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Moves the message to the trash. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#refresh()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Reloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#reply(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Replies to the sender of this message using the reply-to address. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#reply(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Replies to the sender of this message using the reply-to address, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Replies to the sender using the reply-to address and all recipients of this message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String,Object)` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Replies to the sender of this message using the reply-to address and all recipients, with optional arguments. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#star()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Stars the message. |
| `https://developers.google.com/apps-script/reference/gmail/gmail-message#unstar()` | `https://developers.google.com/apps-script/reference/gmail/gmail-message#` | Unstars the message. |

## Detailed documentation

### `createDraftReply(body)`

Creates a draft message replying to the sender of this message 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 original message with an acknowledgment.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.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-message#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReply(body, options)`

Creates a draft message replying to the sender of this message 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];
const message = firstThread.getMessages()[0];
message.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` | when set, devices capable of rendering HTML 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, up to 250 characters. |

#### 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-message#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReplyAll(body)`

Creates a draft message replying to the sender 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 response to all recipients (except those bcc'd) with an
// acknowledgment.
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-message#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String,Object)`

*** ** * ** ***

### `createDraftReplyAll(body, options)`

Creates a draft message replying to the sender of this message 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 response to all recipients (except those bcc'd) using an HTML
// text body.
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.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` | when set, devices capable of rendering HTML 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, up to 250 characters. |

#### 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-message#replyAll(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#createDraftReplyAll(String)`

*** ** * ** ***

### `forward(recipient)`

Forwards this message to new recipients. The size of the email (including headers) is [quota limited](https://developers.google.com/apps-script/guides/services/quotas#current_limitations).

```javascript
// Forward first message of first inbox thread to recipient1 & recipient2,
// both @example.com
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.forward('recipient1@example.com,recipient2@example.com');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `recipient` | `String` | A comma-separated list of email addresses. |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This message, 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-message#forward(String,Object)`

*** ** * ** ***

### `forward(recipient, options)`

Forwards this message to new recipients, with optional arguments.

The email can contain both plain text, and also 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
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.forward('recipient1@example.com,recipient2@example.com', {
  cc: 'myboss@example.com',
  bcc: 'mybosses-boss@example.com,vp@example.com',
});
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `recipient` | `String` | A comma-separated list of email addresses. |
| `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` | when set, devices capable of rendering HTML 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) |
| `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 |
| `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, up to 250 characters. |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This message, 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-message#forward(String)`

*** ** * ** ***

### `getAttachments()`

Gets all the attachments for this message.

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-attachment` --- An array of Blob attachments for this 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/`

*** ** * ** ***

### `getAttachments(options)`

Gets all the attachments for this message.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `options` | `Object` | A JavaScript object that specifies advanced parameters, as listed below. |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `includeInlineImages` | `Boolean` | `true` if the returned array of Blob attachments should include inline images (default is `true`). |
| `includeAttachments` | `Boolean` | `true` if the returned array of Blob attachments should include regular (non-inline) attachments (default is `true`). |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-attachment` --- An array of Blob attachments for this 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/`

*** ** * ** ***

### `getBcc()`

Gets the comma-separated recipients bcc'd on this message.

This is empty for all received messages, by definition.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getBcc());                      // Log bcc'd addresses
```

#### Return


`String` --- The comma-separated recipients bcc'd on this 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-message#getTo()`

*** ** * ** ***

### `getBody()`

Gets the HTML content of the body of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getBody());                     // Log contents of the body
```

#### Return


`String` --- The body content of this 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-message#getSubject()`

*** ** * ** ***

### `getCc()`

Gets the comma-separated recipients cc'd on this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getCc());                       // Log cc'd addresses
```

#### Return


`String` --- The comma-separated recipients cc'd on this 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-message#getTo()`

*** ** * ** ***

### `getDate()`

Gets the date and time of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getDate());  // Log date and time of the message
```

#### Return


`Date` --- The date and time of this 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/`

*** ** * ** ***

### `getFrom()`

Gets the sender of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getFrom());  // Log from address of the message
```

#### Return


`String` --- The email address of the message sender.

#### 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-message#getReplyTo()`

*** ** * ** ***

### `getHeader(name)`

Gets the value of an RFC 2822 header given the header name.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox.
const message = thread.getMessages()[0];           // Get the first message.
Logger.log(
    message.getHeader('Message-ID'));  // Logs the Message-ID RFC 2822 header.
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | The name of the RFC header, without the colon separating it from the value. |

#### Return


`String` --- The value of the header, or an empty string if the header doesn't exist in the 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/`

*** ** * ** ***

### `getId()`

Gets the ID of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
const id = message.getId();
const messageById = GmailApp.getMessageById(id);
Logger.log(
    message.getSubject() === messageById.getMessage());  // Always logs true
```

#### Return


`String` --- The message ID.

*** ** * ** ***

### `getPlainBody()`

Gets the content of the body of this message without HTML formatting. This is more complex than
`getBody()` and takes longer.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getPlainBody());                // Log contents of the body
```

#### Return


`String` --- The plain body content of this 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-message#getSubject()`

*** ** * ** ***

### `getRawContent()`

Gets the raw content of this message. This is equivalent to "Show Original" in the Gmail UI.

#### Return


`String` --- The raw content of this 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/`

*** ** * ** ***

### `getReplyTo()`

Gets the reply-to address of this message (usually the sender).

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getReplyTo());                  // Logs reply-to address
```

#### Return


`String` --- The email address for replies.

#### 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-message#getCc()`

*** ** * ** ***

### `getSubject()`

Gets the subject of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getSubject());                  // Log subject line
```

#### Return


`String` --- The subject of this 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-message#getAttachments()`

*** ** * ** ***

### `getThread()`

Gets the thread that contains this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(
    message.getThread().getFirstMessageSubject() ===
        thread.getFirstMessageSubject(),
);  // Always logs true
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-thread` --- The GmailThread that contains this 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/`

*** ** * ** ***

### `getTo()`

Gets the comma-separated recipients of this message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(message.getTo());  // Log the recipient of message
```

#### Return


`String` --- The comma-separated recipients of this 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-message#getCc()`

*** ** * ** ***

### `isDraft()`

Gets whether this message is a draft.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is draft? ${message.isDraft()}`);
```

#### Return


`Boolean` --- Whether this message is a draft.

#### 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()`

Gets whether this message is a chat.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is a chat? ${message.isInChats()}`);
```

#### Return


`Boolean` --- Whether this message is a chat.

*** ** * ** ***

### `isInInbox()`

Gets whether this message is in the inbox.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is in inbox? ${message.isInInbox()}`);
```

#### Return


`Boolean` --- Whether this message 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 message is in the priority inbox; returns `false` otherwise.

```javascript
const thread = GmailApp.getPriorityInboxThreads(
    0, 1)[0];  // Get first thread in priority inbox
const messages = thread.getMessages();
for (let i = 0; i < messages.length; i++) {
  // At least one of the messages is in priority inbox
  Logger.log(`is in priority inbox? ${messages[i].isInPriorityInbox()}`);
}
```

#### Return


`Boolean` --- Whether this message 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/`

*** ** * ** ***

### `isInTrash()`

Gets whether this message is in the trash.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is in the trash? ${message.isInTrash()}`);
```

#### Return


`Boolean` --- Whether this message is in the trash.

*** ** * ** ***

### `isStarred()`

Gets whether this message is starred.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is starred? ${message.isStarred()}`);
```

#### Return


`Boolean` --- Whether this message is starred.

*** ** * ** ***

### `isUnread()`

Gets whether this message is unread.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
Logger.log(`is unread? ${message.isUnread()}`);
```

#### Return


`Boolean` --- The unread status of this 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/`

*** ** * ** ***

### `markRead()`

Marks the message as read.

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

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This GmailMessage, 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-message#isUnread()`

*** ** * ** ***

### `markUnread()`

Marks the message as unread.

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

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This GmailMessage, 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-message#isUnread()`

*** ** * ** ***

### `moveToTrash()`

Moves the message to the trash.

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

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This GmailMessage, 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-message#isInTrash()`

*** ** * ** ***

### `refresh()`

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

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
// .. Do bunch of stuff here
message.refresh();  // Make sure it's up to date
// Do more stuff to message
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This message 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/`

*** ** * ** ***

### `reply(body)`

Replies to the sender of this message 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
// Respond to author of message with acknowledgment
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.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-message#` --- This message, 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-message#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String,Object)`

*** ** * ** ***

### `reply(body, options)`

Replies to the sender of this message using the reply-to address, with optional arguments.

The email can contain both plain text, and also 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
// Respond with HTML body text
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.reply('incapable of HTML', {
  htmlBody: '<b>some HTML body text</b>',
  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 |
|---|---|---|
| `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` | when set, devices capable of rendering HTML 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) |
| `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 |
| `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, up to 250 characters. |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This message, 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-message#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String,Object)`

*** ** * ** ***

### `replyAll(body)`

Replies to the sender 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
// Respond to all recipients (except bcc'd) of last email in thread with
// acknowledgment
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.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-message#` --- This message,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-message#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String,Object)`

*** ** * ** ***

### `replyAll(body, options)`

Replies to the sender of this message using the reply-to address and all recipients, with
optional arguments.

The email can contain both plain text, and also 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
// Respond with HTML body text
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
const message = firstThread.getMessages()[0];
message.replyAll('incapable of HTML', {
  htmlBody: '<b>some HTML body text</b>',
  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 |
|---|---|---|
| `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` | when set, devices capable of rendering HTML 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) |
| `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 |
| `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, up to 250 characters. |

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This message, 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-message#reply(String)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#reply(String,Object)`
- `https://developers.google.com/apps-script/reference/gmail/gmail-message#replyAll(String)`

*** ** * ** ***

### `star()`

Stars the message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
message.star();                                    // Star the message
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This GmailMessage, 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-message#unstar()`

*** ** * ** ***

### `unstar()`

Unstars the message.

```javascript
const thread = GmailApp.getInboxThreads(0, 1)[0];  // Get first thread in inbox
const message = thread.getMessages()[0];           // Get first message
message.unstar();                                  // Unstar the message
```

#### Return


`https://developers.google.com/apps-script/reference/gmail/gmail-message#` --- This GmailMessage, 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-message#star()`