Class GmailMessage | Apps Script | Google for Developers (original) (raw)
Google Workspace services
Calendar
- Overview
- CalendarApp
- Classes
- Calendar
- CalendarEvent
- CalendarEventSeries
- EventGuest
- EventRecurrence
- RecurrenceRule
- Enums
- Color
- EventColor
- EventTransparency
- EventType
- GuestStatus
- Visibility
- Advanced services
- Calendar API
Docs
- Overview
- DocumentApp
- Classes
- Body
- Bookmark
- ContainerElement
- Date
- Document
- DocumentTab
- Equation
- EquationFunction
- EquationFunctionArgumentSeparator
- EquationSymbol
- FooterSection
- Footnote
- FootnoteSection
- HeaderSection
- HorizontalRule
- InlineDrawing
- InlineImage
- ListItem
- NamedRange
- PageBreak
- Paragraph
- Person
- Position
- PositionedImage
- Range
- RangeBuilder
- RangeElement
- RichLink
- Tab
- Table
- TableCell
- TableOfContents
- TableRow
- Text
- UnsupportedElement
- Interfaces
- Element
- Enums
- Attribute
- ElementType
- FontFamily
- GlyphType
- HorizontalAlignment
- ParagraphHeading
- PositionedLayout
- TabType
- TextAlignment
- VerticalAlignment
- Advanced services
- Docs API
Drive
- Overview
- DriveApp
- Classes
- File
- FileIterator
- Folder
- FolderIterator
- User
- Enums
- Access
- Permission
- Advanced services
- Drive API
- Drive Activity API
- Drive Labels API
Forms
- Overview
- FormApp
- Classes
- CheckboxGridItem
- CheckboxGridValidation
- CheckboxGridValidationBuilder
- CheckboxItem
- CheckboxValidation
- CheckboxValidationBuilder
- Choice
- DateItem
- DateTimeItem
- DurationItem
- Form
- FormResponse
- GridItem
- GridValidation
- GridValidationBuilder
- ImageItem
- ItemResponse
- ListItem
- MultipleChoiceItem
- PageBreakItem
- ParagraphTextItem
- ParagraphTextValidation
- ParagraphTextValidationBuilder
- QuizFeedback
- QuizFeedbackBuilder
- RatingItem
- ScaleItem
- SectionHeaderItem
- TextItem
- TextValidation
- TextValidationBuilder
- TimeItem
- VideoItem
- Interfaces
- Item
- Enums
- Alignment
- DestinationType
- FeedbackType
- ItemType
- PageNavigationType
- RatingIconType
Gmail
- Overview
- GmailApp
- Classes
- GmailAttachment
- GmailDraft
- GmailLabel
- GmailMessage
- GmailThread
- Advanced services
- Gmail API
Sheets
- Overview
- SpreadsheetApp
- Classes
- Banding
- BooleanCondition
- CellImage
- CellImageBuilder
- Color
- ColorBuilder
- ConditionalFormatRule
- ConditionalFormatRuleBuilder
- ContainerInfo
- DataSource for Connected Sheets
* BigQueryDataSourceSpec
* BigQueryDataSourceSpecBuilder
* DataExecutionStatus
* LookerDataSourceSpec
* LookerDataSourceSpecBuilder
* DataSource
* DataSourceChart
* DataSourceColumn
* DataSourceFormula
* DataSourceParameter
* DataSourcePivotTable
* DataSourceRefreshSchedule
* DataSourceRefreshScheduleFrequency
* DataSourceSheet
* DataSourceSheetFilter
* DataSourceSpec
* DataSourceSpecBuilder
* DataSourceTable
* DataSourceTableColumn
* DataSourceTableFilter - DataValidation
- DataValidationBuilder
- DateTimeGroupingRule
- DeveloperMetadata
- DeveloperMetadataFinder
- DeveloperMetadataLocation
- Drawing
- EmbeddedAreaChartBuilder
- EmbeddedBarChartBuilder
- EmbeddedChart
- EmbeddedChartBuilder
- EmbeddedColumnChartBuilder
- EmbeddedComboChartBuilder
- EmbeddedHistogramChartBuilder
- EmbeddedLineChartBuilder
- EmbeddedPieChartBuilder
- EmbeddedScatterChartBuilder
- EmbeddedTableChartBuilder
- Filter
- FilterCriteria
- FilterCriteriaBuilder
- GradientCondition
- Group
- NamedRange
- OverGridImage
- PageProtection
- PivotFilter
- PivotGroup
- PivotGroupLimit
- PivotTable
- PivotValue
- Protection
- Range
- RangeList
- RichTextValue
- RichTextValueBuilder
- Selection
- Sheet
- Slicer
- SortSpec
- Spreadsheet
- SpreadsheetTheme
- TextFinder
- TextRotation
- TextStyle
- TextStyleBuilder
- ThemeColor
- Enums
- AutoFillSeries
- BandingTheme
- BooleanCriteria
- BorderStyle
- CopyPasteType
- DataValidationCriteria
- DateTimeGroupingRuleType
- DeveloperMetadataLocationType
- DeveloperMetadataVisibility
- Dimension
- Direction
- FrequencyType
- GroupControlTogglePosition
- InterpolationType
- PivotTableSummarizeFunction
- PivotValueDisplayType
- ProtectionType
- RecalculationInterval
- RelativeDate
- SheetType
- SortOrder
- TextDirection
- TextToColumnsDelimiter
- ThemeColorType
- ValueType
- WrapStrategy
- Advanced services
- Sheets API
Slides
- Overview
- SlidesApp
- Classes
- AffineTransform
- AffineTransformBuilder
- AutoText
- Autofit
- Border
- Color
- ColorScheme
- ConnectionSite
- Fill
- Group
- Image
- Layout
- Line
- LineFill
- Link
- List
- ListStyle
- Master
- NotesMaster
- NotesPage
- Page
- PageBackground
- PageElement
- PageElementRange
- PageRange
- Paragraph
- ParagraphStyle
- PictureFill
- Point
- Presentation
- Selection
- Shape
- SheetsChart
- Slide
- SolidFill
- SpeakerSpotlight
- Table
- TableCell
- TableCellRange
- TableColumn
- TableRow
- TextRange
- TextStyle
- ThemeColor
- Video
- WordArt
- Enums
- AlignmentPosition
- ArrowStyle
- AutoTextType
- AutofitType
- CellMergeState
- ContentAlignment
- DashStyle
- FillType
- LineCategory
- LineFillType
- LineType
- LinkType
- ListPreset
- PageBackgroundType
- PageElementType
- PageType
- ParagraphAlignment
- PlaceholderType
- PredefinedLayout
- SelectionType
- ShapeType
- SheetsChartEmbedType
- SlideLinkingMode
- SlidePosition
- SpacingMode
- TextBaselineOffset
- TextDirection
- ThemeColorType
- VideoSourceType
- Advanced services
- Slides API
More...
- Groups
* Overview
* GroupsApp
* Classes
* Group
* Enums
* Role
* Advanced services
* Cloud Identity Groups API
* Migrate from Groups Service - People
* Advanced services
* People API
* Migrate from Contacts service
* Contacts
* Overview
* ContactsApp
* Classes
* AddressField
* CompanyField
* Contact
* ContactGroup
* CustomField
* DateField
* EmailField
* IMField
* PhoneField
* UrlField
* Enums
* ExtendedField
* Field
* Gender
* Priority
* Sensitivity
- Groups
Other Google services
Google Maps
YouTube
- Advanced services
- YouTube Data API
- YouTube Analytics API
- YouTube Content ID API
More...
- Google Ads & Merchant Center
- Google Data Studio
* Overview
* DataStudioApp
* Classes
* BigQueryConfig
* Checkbox
* CommunityConnector
* Config
* DebugError
* Field
* Fields
* GetAuthTypeResponse
* GetDataResponse
* GetSchemaResponse
* Info
* OptionBuilder
* SelectMultiple
* SelectSingle
* SetCredentialsResponse
* TextArea
* TextInput
* UserError
* Enums
* AggregationType
* AuthType
* BigQueryParameterType
* FieldType
Utility services
API & database connections
- JDBC
* Overview
* Jdbc
* Classes
* JdbcArray
* JdbcBlob
* JdbcCallableStatement
* JdbcClob
* JdbcConnection
* JdbcDatabaseMetaData
* JdbcDate
* JdbcParameterMetaData
* JdbcPreparedStatement
* JdbcRef
* JdbcResultSet
* JdbcResultSetMetaData
* JdbcRowId
* JdbcSQLXML
* JdbcSavepoint
* JdbcStatement
* JdbcStruct
* JdbcTime
* JdbcTimestamp
- JDBC
Data usability & optimization
- Optimization
* Overview
* LinearOptimizationService
* Classes
* LinearOptimizationConstraint
* LinearOptimizationEngine
* LinearOptimizationSolution
* Enums
* Status
* VariableType - XML
* Overview
* XmlService
* Classes
* Attribute
* Cdata
* Comment
* DocType
* Document
* Element
* EntityRef
* Format
* Namespace
* ProcessingInstruction
* Text
* Interfaces
* Content
* Enums
* ContentType
- Optimization
HTML & content
- Charts
* Overview
* Charts
* Classes
* AreaChartBuilder
* BarChartBuilder
* Chart
* ChartOptions
* ColumnChartBuilder
* DataTable
* DataTableBuilder
* DataViewDefinition
* DataViewDefinitionBuilder
* LineChartBuilder
* NumberRangeFilterBuilder
* PieChartBuilder
* ScatterChartBuilder
* StringFilterBuilder
* TableChartBuilder
* TextStyle
* TextStyleBuilder
* Interfaces
* DataTableSource
* Enums
* ChartHiddenDimensionStrategy
* ChartMergeStrategy
* ChartType
* ColumnType
* CurveStyle
* MatchType
* Orientation
* PickerValuesLayout
* PointStyle
* Position - HTML
* Overview
* google.script.history (client-side)
* google.script.host (client-side)
* google.script.run (client-side)
* google.script.url (client-side)
* HtmlService
* Classes
* HtmlOutput
* HtmlOutputMetaTag
* HtmlTemplate
* Enums
* SandboxMode
* XFrameOptionsMode
- Charts
Script execution & information
- Base
* Overview
* Browser
* Logger
* MimeType
* Session
* console
* Classes
* Blob
* Menu
* PromptResponse
* RgbColor
* Ui
* User
* Interfaces
* BlobSource
* Enums
* Button
* ButtonSet
* ColorType
* Month
* Weekday - Script
* Overview
* ScriptApp
* Classes
* AuthorizationInfo
* CalendarTriggerBuilder
* ClockTriggerBuilder
* DocumentTriggerBuilder
* FormTriggerBuilder
* Service
* SpreadsheetTriggerBuilder
* StateTokenBuilder
* Trigger
* TriggerBuilder
* Enums
* AuthMode
* AuthorizationStatus
* EventType
* InstallationSource
* TriggerSource
- Base
Script project resources
Manifest
Google Workspace add-ons
Services
- Card
* Overview
* CardService
* Classes
* Action
* ActionResponse
* ActionResponseBuilder
* ActionStatus
* Attachment
* AuthorizationAction
* AuthorizationException
* BorderStyle
* Button
* ButtonSet
* CalendarEventActionResponse
* CalendarEventActionResponseBuilder
* Card
* CardAction
* CardBuilder
* CardHeader
* CardSection
* CardWithId
* Carousel
* CarouselCard
* ChatActionResponse
* ChatClientDataSource
* ChatResponse
* ChatResponseBuilder
* ChatSpaceDataSource
* Chip
* ChipList
* CollapseControl
* Column
* Columns
* ComposeActionResponse
* ComposeActionResponseBuilder
* DatePicker
* DateTimePicker
* DecoratedText
* Dialog
* DialogAction
* Divider
* DriveItemsSelectedActionResponse
* DriveItemsSelectedActionResponseBuilder
* EditorFileScopeActionResponse
* EditorFileScopeActionResponseBuilder
* FixedFooter
* Grid
* GridItem
* HostAppDataSource
* IconImage
* Image
* ImageButton
* ImageComponent
* ImageCropStyle
* KeyValue
* LinkPreview
* MaterialIcon
* Navigation
* Notification
* OpenLink
* OverflowMenu
* OverflowMenuItem
* PlatformDataSource
* SelectionInput
* Suggestions
* SuggestionsResponse
* SuggestionsResponseBuilder
* Switch
* TextButton
* TextInput
* TextParagraph
* TimePicker
* UniversalActionResponse
* UniversalActionResponseBuilder
* UpdateDraftActionResponse
* UpdateDraftActionResponseBuilder
* UpdateDraftBccRecipientsAction
* UpdateDraftBodyAction
* UpdateDraftCcRecipientsAction
* UpdateDraftSubjectAction
* UpdateDraftToRecipientsAction
* UpdatedWidget
* Validation
* Widget
* Enums
* BorderType
* ChipListLayout
* CommonDataSource
* ComposedEmailType
* ContentType
* DisplayStyle
* GridItemLayout
* HorizontalAlignment
* HorizontalSizeStyle
* Icon
* ImageButtonStyle
* ImageCropType
* ImageStyle
* InputType
* Interaction
* LoadIndicator
* OnClose
* OpenAs
* ResponseType
* SelectionInputType
* Status
* SwitchControlType
* TextButtonStyle
* UpdateDraftBodyType
* VerticalAlignment
* WrapStyle - Conferencing Data
* Overview
* ConferenceDataService
* Classes
* ConferenceData
* ConferenceDataBuilder
* ConferenceError
* ConferenceParameter
* EntryPoint
* Enums
* ConferenceErrorType
* EntryPointFeature
* EntryPointType
- Card
Manifest
Apps Script API
v1
- Overview
- REST Resources
- Types
- ExecuteStreamResponse
- ExecutionError
- ExecutionResponse
- File
- LocalizedMessage
- NullValue
Class GmailMessage
Stay organized with collections Save and categorize content based on your preferences.
GmailMessage
A message in a user's Gmail account.
Methods
Method | Return type | Brief description |
---|---|---|
createDraftReply(body) | GmailDraft | Creates a draft message replying to the sender of this message using the reply-to address. |
createDraftReply(body, options) | GmailDraft | Creates a draft message replying to the sender of this message using the reply-to address, with optional arguments. |
createDraftReplyAll(body) | GmailDraft | Creates a draft message replying to the sender using the reply-to address and all recipients of this message. |
createDraftReplyAll(body, options) | GmailDraft | Creates a draft message replying to the sender of this message using the reply-to address and all recipients, with optional arguments. |
forward(recipient) | GmailMessage | Forwards this message to new recipients. |
forward(recipient, options) | GmailMessage | Forwards this message to new recipients, with optional arguments. |
getAttachments() | GmailAttachment[] | Gets all the attachments for this message. |
getAttachments(options) | GmailAttachment[] | Gets all the attachments for this message. |
getBcc() | String | Gets the comma-separated recipients bcc'd on this message. |
getBody() | String | Gets the HTML content of the body of this message. |
getCc() | String | Gets the comma-separated recipients cc'd on this message. |
getDate() | Date | Gets the date and time of this message. |
getFrom() | String | Gets the sender of this message. |
getHeader(name) | String | Gets the value of an RFC 2822 header given the header name. |
getId() | String | Gets the ID of this message. |
getPlainBody() | String | Gets the content of the body of this message without HTML formatting. |
getRawContent() | String | Gets the raw content of this message. |
getReplyTo() | String | Gets the reply-to address of this message (usually the sender). |
getSubject() | String | Gets the subject of this message. |
getThread() | GmailThread | Gets the thread that contains this message. |
getTo() | String | Gets the comma-separated recipients of this message. |
isDraft() | Boolean | Gets whether this message is a draft. |
isInChats() | Boolean | Gets whether this message is a chat. |
isInInbox() | Boolean | Gets whether this message is in the inbox. |
isInPriorityInbox() | Boolean | Returns true if this message is in the priority inbox; returns false otherwise. |
isInTrash() | Boolean | Gets whether this message is in the trash. |
isStarred() | Boolean | Gets whether this message is starred. |
isUnread() | Boolean | Gets whether this message is unread. |
markRead() | GmailMessage | Marks the message as read. |
markUnread() | GmailMessage | Marks the message as unread. |
moveToTrash() | GmailMessage | Moves the message to the trash. |
refresh() | GmailMessage | Reloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
reply(body) | GmailMessage | Replies to the sender of this message using the reply-to address. |
reply(body, options) | GmailMessage | Replies to the sender of this message using the reply-to address, with optional arguments. |
replyAll(body) | GmailMessage | Replies to the sender using the reply-to address and all recipients of this message. |
replyAll(body, options) | GmailMessage | Replies to the sender of this message using the reply-to address and all recipients, with optional arguments. |
star() | GmailMessage | Stars the message. |
unstar() | GmailMessage | 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.
// 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
[GmailDraft](/apps-script/reference/gmail/gmail-draft)
— The newly created draft message.
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%28String%29)
[createDraftReply(body, options)](#createDraftReply%28String,Object%29)
[createDraftReplyAll(body)](#createDraftReplyAll%28String%29)
[createDraftReplyAll(body, options)](#createDraftReplyAll%28String,Object%29)
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.
// 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: 'some HTML body text', 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 | BlobSource[] | 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 GmailApp.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 (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format |
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
[GmailDraft](/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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[reply(body, options)](#reply%28String,Object%29)
[createDraftReply(body)](#createDraftReply%28String%29)
[createDraftReplyAll(body)](#createDraftReplyAll%28String%29)
[createDraftReplyAll(body, options)](#createDraftReplyAll%28String,Object%29)
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.
// 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
[GmailDraft](/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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[replyAll(body)](#replyAll%28String%29)
[createDraftReply(body)](#createDraftReply%28String%29)
[createDraftReply(body, options)](#createDraftReply%28String,Object%29)
[createDraftReplyAll(body, options)](#createDraftReplyAll%28String,Object%29)
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.
// 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: 'some HTML body text', 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 | BlobSource[] | 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 GmailApp.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 (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format |
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
[GmailDraft](/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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[replyAll(body, options)](#replyAll%28String,Object%29)
[createDraftReply(body)](#createDraftReply%28String%29)
[createDraftReply(body, options)](#createDraftReply%28String,Object%29)
[createDraftReplyAll(body)](#createDraftReplyAll%28String%29)
forward(recipient)
Forwards this message to new recipients. The size of the email (including headers) is quota limited.
// 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
[GmailMessage](#)
— This message, 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
[forward(recipient, options)](#forward%28String,Object%29)
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.
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 | BlobSource[] | 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 GmailApp.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 (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format |
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
[GmailMessage](#)
— This message, 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
[forward(recipient)](#forward%28String%29)
getAttachments()
Gets all the attachments for this message.
Return
[GmailAttachment[]](/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 or appropriate scopes from the related REST API:
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
[GmailAttachment[]](/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 or appropriate scopes from the related REST API:
https://mail.google.com/
getBcc()
Gets the comma-separated recipients bcc'd on this message.
This is empty for all received messages, by definition.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getTo()](#getTo%28%29)
getBody()
Gets the HTML content of the body of this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getSubject()](#getSubject%28%29)
getCc()
Gets the comma-separated recipients cc'd on this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getTo()](#getTo%28%29)
getDate()
Gets the date and time of this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
getFrom()
Gets the sender of this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getReplyTo()](#getReplyTo%28%29)
getId()
Gets the ID of this message.
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 thangetBody()
and takes longer.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getSubject()](#getSubject%28%29)
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 or appropriate scopes from the related REST API:
https://mail.google.com/
getReplyTo()
Gets the reply-to address of this message (usually the sender).
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getCc()](#getCc%28%29)
getSubject()
Gets the subject of this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getAttachments()](#getAttachments%28%29)
getThread()
Gets the thread that contains this message.
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
[GmailThread](/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 or appropriate scopes from the related REST API:
https://mail.google.com/
getTo()
Gets the comma-separated recipients of this message.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
See also
[getCc()](#getCc%28%29)
isDraft()
Gets whether this message is a draft.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
isInChats()
Gets whether this message is a chat.
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.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
isInPriorityInbox()
Returns true
if this message is in the priority inbox; returns false
otherwise.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
isInTrash()
Gets whether this message is in the trash.
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.
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.
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 or appropriate scopes from the related REST API:
https://mail.google.com/
markRead()
Marks the message as read.
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
[GmailMessage](#)
— This GmailMessage, 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
[isUnread()](#isUnread%28%29)
markUnread()
Marks the message as unread.
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
[GmailMessage](#)
— This GmailMessage, 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
[isUnread()](#isUnread%28%29)
moveToTrash()
Moves the message to the trash.
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
[GmailMessage](#)
— This GmailMessage, 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
[isInTrash()](#isInTrash%28%29)
refresh()
Reloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed).
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
[GmailMessage](#)
— This message 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/
reply(body)
Replies to the sender of this message using the reply-to address. The size of the email (including headers) is quota limited.
// 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
[GmailMessage](#)
— This message, 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%28String,Object%29)
[replyAll(body)](#replyAll%28String%29)
[replyAll(body, options)](#replyAll%28String,Object%29)
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.
// Respond with HTML body text const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.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 |
---|---|---|
attachments | BlobSource[] | 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 GmailApp.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 (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format |
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
[GmailMessage](#)
— This message, 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%28String%29)
[replyAll(body)](#replyAll%28String%29)
[replyAll(body, options)](#replyAll%28String,Object%29)
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.
// 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
[GmailMessage](#)
— This message,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%28String%29)
[reply(body, options)](#reply%28String,Object%29)
[replyAll(body, options)](#replyAll%28String,Object%29)
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.
// Respond with HTML body text const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.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 |
---|---|---|
attachments | BlobSource[] | 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 GmailApp.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 (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format |
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
[GmailMessage](#)
— This message, 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%28String%29)
[reply(body, options)](#reply%28String,Object%29)
[replyAll(body)](#replyAll%28String%29)
star()
Stars the message.
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
[GmailMessage](#)
— This GmailMessage, 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
[unstar()](#unstar%28%29)
unstar()
Unstars the message.
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
[GmailMessage](#)
— This GmailMessage, 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
[star()](#star%28%29)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-03 UTC.