Class GmailThread

Gmail Thread

A thread in a user's Gmail account.

Methods

Method Return type Brief description
Gmail Thread Adds this label to the thread.
Gmail Draft Creates a draft message replying to the sender of the last message in this thread using the reply-to address.
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.
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.
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.
String Gets the subject of the first message in the thread.
String Gets the ID of this thread.
Gmail Label[] Returns the user-created labels on this thread.
Date Gets the date of this thread's most recent message.
Integer Returns the number of messages in the thread.
Gmail Message[] Gets the messages in this thread.
String Gets a permalink for this thread.
Boolean Returns whether the thread has any starred messages.
Boolean Returns whether the thread is marked as important.
Boolean Returns whether the thread is labeled a chat.
Boolean Returns whether the thread is in the inbox.
Boolean Returns true if this thread is in the priority inbox; returns false otherwise.
Boolean Returns whether the thread is marked as spam.
Boolean Returns whether the thread is in the trash.
Boolean Returns whether the thread has any unread messages.
Gmail Thread Marks this thread as important.
Gmail Thread Marks this thread as read.
Gmail Thread Marks this thread as unimportant.
Gmail Thread Marks this thread as unread.
Gmail Thread Moves this thread to the archive.
Gmail Thread Moves this thread to the inbox.
Gmail Thread Moves this thread to spam.
Gmail Thread Moves this thread to the trash.
Gmail Thread Reloads this thread, and associated state from Gmail (useful in case the labels, read state, etc., have changed).
Gmail Thread Removes this label from the thread.
Gmail Thread Reply to the sender of the last message on this thread using the replyTo address.
Gmail Thread Reply to the sender of the last message on this thread using the replyTo address, with optional arguments.
Gmail Thread Reply to the sender (using the replyTo address), and all recipients of the last message on this thread.
Gmail Thread Reply to the sender (using the reply To address), and all recipients of the last message on this thread, with optional arguments.

Detailed documentation

add Label(label)

Adds this label to the thread.

 // 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
Gmail Label the label to apply to this thread

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


create Draft Reply(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 .

 // 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

Gmail Draft — the newly created draft message

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


create Draft Reply(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 .

 // 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
Blob Source[] 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 Gmail App.getAliases()
html Body
String if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional inline Images field in HTML body if you have inlined images for your email
inline Images
Object a JavaScript object containing a mapping from image key ( String ) to image data ( Blob Source ); this assumes that the html Body 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)
reply To
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

Gmail Draft — the newly created draft message

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


create Draft Reply All(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 .

 // 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

Gmail Draft — the newly created draft message

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


create Draft Reply All(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 .

 // 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
Blob Source[] 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 Gmail App.getAliases()
html Body
String if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional inline Images field in HTML body if you have inlined images for your email
inline Images
Object a JavaScript object containing a mapping from image key ( String ) to image data ( Blob Source ); this assumes that the html Body 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)
reply To
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

Gmail Draft — the newly created draft message

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


get First Message Subject()

Gets the subject of the first message in the thread.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


get Id()

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 get Messages()[0].getId() instead.

 // 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


get Labels()

Returns the user-created labels on this thread.

 // 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

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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

get Last Message Date()

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

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


get Message Count()

Returns the number of messages in the thread.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


get Messages()

Gets the messages in this thread.

 // 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

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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


Gets a permalink for this thread.

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

 // 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


has Starred Messages()

Returns whether the thread has any starred messages.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is Important()

Returns whether the thread is marked as important.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is In Chats()

Returns whether the thread is labeled a chat.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is In Inbox()

Returns whether the thread is in the inbox.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is In Priority Inbox()

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

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is In Spam()

Returns whether the thread is marked as spam.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is In Trash()

Returns whether the thread is in the trash.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

is Unread()

Returns whether the thread has any unread messages.

 // 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 or appropriate scopes from the related REST API :

  • https://mail.google.com/

mark Important()

Marks this thread as important.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


mark Read()

Marks this thread as read.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


mark Unimportant()

Marks this thread as unimportant.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


mark Unread()

Marks this thread as unread.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


move To Archive()

Moves this thread to the archive.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

move To Inbox()

Moves this thread to the inbox.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

move To Spam()

Moves this thread to spam.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

move To Trash()

Moves this thread to the trash.

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

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

refresh()

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

 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

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

remove Label(label)

Removes this label from the thread.

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

Parameters

Name Type Description
label
Gmail Label the label to remove from this thread

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


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.

 // 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

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


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.

 // 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
html Body
String if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional inline Images 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 Gmail App.getAliases()
reply To
String an email address to use as the default reply-to address (default: the user's email address)
no Reply
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
Blob Source[] an array of files to send with the email
inline Images
Object a JavaScript object containing a mapping from image key ( String ) to image data ( Blob Source ); this assumes that the html Body parameter is used and contains references to these images in the format <img src="cid:imageKey" />

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


reply All(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.

 // 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

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also


reply All(body, options)

Reply to the sender (using the reply To 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.

 // 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
html Body
String if set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional inline Images 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 Gmail App.getAliases()
reply To
String an email address to use as the default reply-to address (default: the user's email address)
no Reply
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
Blob Source[] an array of files to send with the email
inline Images
Object a JavaScript object containing a mapping from image key ( String ) to image data ( Blob Source ); this assumes that the html Body parameter is used and contains references to these images in the format <img src="cid:imageKey" />

Return

Gmail Thread — this thread, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API :

  • https://mail.google.com/

See also

Create a Mobile Website
View Site in Mobile | Classic
Share by: