Object reference
Gmail message
A GmailMessage is one email inside a Gmail thread. Call getFrom(), getSubject(), getDate(), getPlainBody(), or getAttachments() to inspect that single message.
GmailApp.GmailMessageStart here
Get this object first
Search for a thread with GmailApp.search, then take the first message from it.
function showFirstSearchedMessageSubject() {
const threads = GmailApp.search('newer_than:7d', 0, 1);
if (!threads.length) return;
const message = threads[0].getMessages()[0];
Logger.log(message.getSubject());
} Then use it
Common actions
Choose an action, then open its example only when you need the code.
Read the sender, subject, and date
This reads three details from the first message of a recent search and leaves the message unchanged.
GmailApp.GmailMessageShow example code
function logFirstSearchedMessageDetails() {
const threads = GmailApp.search('newer_than:7d', 0, 1);
if (!threads.length) return;
const message = threads[0].getMessages()[0];
Logger.log('From: ' + message.getFrom());
Logger.log('Subject: ' + message.getSubject());
Logger.log('Date: ' + message.getDate());
} Get the plain text body
This records only the length of the plain text body, so no email content is copied into the execution log.
GmailApp.GmailMessageShow example code
function logFirstSearchedMessageBodyLength() {
const threads = GmailApp.search('newer_than:7d', 0, 1);
if (!threads.length) return;
const message = threads[0].getMessages()[0];
const plainBody = message.getPlainBody();
Logger.log('Plain text body length: ' + plainBody.length);
} List the attachment names
This lists the file names attached to the message and does not download or save the attachments.
GmailApp.GmailMessageShow example code
function logFirstSearchedMessageAttachmentNames() {
const threads = GmailApp.search('has:attachment newer_than:7d', 0, 1);
if (!threads.length) return;
const message = threads[0].getMessages()[0];
const names = message.getAttachments().map((attachment) => attachment.getName());
Logger.log(names.join(', ') || 'No attachments');
} Technical reference
Exact names and signatures
Generated runtime and signature facts stay separate from the beginner actions above. Open method details only when you need them.
At a glance
- Service
- GmailApp
- Reference symbol
GmailApp.GmailMessage- Object
GmailMessage- Runtime
- From signature data
Methods and signatures
Browse 32 methods
createDraftReply
- createDraftReply(body: string): GmailApp.GmailDraft
- createDraftReply(body: string, options: unknown): GmailApp.GmailDraft
createDraftReplyAll
- createDraftReplyAll(body: string): GmailApp.GmailDraft
- createDraftReplyAll(body: string, options: unknown): GmailApp.GmailDraft
forward
- forward(recipient: string): GmailApp.GmailMessage
- forward(recipient: string, options: GmailApp.GmailAdvancedParameters): GmailApp.GmailMessage
getAttachments
- getAttachments(): GmailApp.GmailAttachment[]
- getAttachments(options: GmailApp.GmailAttachmentOptions): GmailApp.GmailAttachment[]
getBcc
- getBcc(): string
getBody
- getBody(): string
getCc
- getCc(): string
getDate
- getDate(): Date
getFrom
- getFrom(): string
getHeader
- getHeader(name: string): string
getId
- getId(): string
getPlainBody
- getPlainBody(): string
getRawContent
- getRawContent(): string
getReplyTo
- getReplyTo(): string
getSubject
- getSubject(): string
getThread
- getThread(): GmailApp.GmailThread
getTo
- getTo(): string
isDraft
- isDraft(): boolean
isInChats
- isInChats(): boolean
isInInbox
- isInInbox(): boolean
isInPriorityInbox
- isInPriorityInbox(): boolean
isInTrash
- isInTrash(): boolean
isStarred
- isStarred(): boolean
isUnread
- isUnread(): boolean
markRead
- markRead(): GmailApp.GmailMessage
markUnread
- markUnread(): GmailApp.GmailMessage
moveToTrash
- moveToTrash(): GmailApp.GmailMessage
refresh
- refresh(): GmailApp.GmailMessage
reply
- reply(body: string): GmailApp.GmailMessage
- reply(body: string, options: GmailApp.GmailAdvancedParameters): GmailApp.GmailMessage
replyAll
- replyAll(body: string): GmailApp.GmailMessage
- replyAll(body: string, options: unknown): GmailApp.GmailMessage
star
- star(): GmailApp.GmailMessage
unstar
- unstar(): GmailApp.GmailMessage
Need the whole workflow?
Return to a task guide
Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.
Browse Gmail tasks